I have String as below,
value = {"name":"John","timeStamp":"2020-08-11T13:31:31"}
My Pojo class is,
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
class Person{
private String name;
@JsonFormat(pattern = "YYYY-MM-dd HH:mm", shape = JsonFormat.Shape.STRING)
@JsonSerialize(using = LocalDateTimeSerializer.class)
private LocalDateTime timeStamp;
}
I use the below artifact, as per https://github.com/FasterXML/jackson-modules-java8
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-parameter-names</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.11.1</version>
</dependency>
I use the below config,
final ObjectMapper objectMapper = JsonMapper.builder()
.addModule(new ParameterNamesModule())
.addModule(new Jdk8Module())
.addModule(new JavaTimeModule())
.build();
objectMapper.readValue(value, Person.class)
I'm getting the below exception,
Caused by: java.io.NotSerializableException: java.time.format.DateTimeFormatter
I tried with the below in the timeStamp also, but no luck
@JsonFormat(pattern = "yyy-MM-ddThh:mm:ss")