I've a LocalDateTime field with @JsonFormat
@JsonFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'")
private LocalDateTime dateTime;
When Jackson try to parse a date like 2018-11-28T15:24:00.000Z a exception is throwed
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of java.time.LocalDateTime: no String-argument constructor/factory method to deserialize from String value ('2018-11-28T15:24:00.000Z')
In my pom.xml i have:
- Spring boot 1.5.7
- jackson-datatype-jdk8
- jackson-datatype-jsr310
My ObjectMapper Bean:
@Bean
public ObjectMapper postConstruct() {
return this.builder
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.defaultUseWrapper(false)
.build();
}
I also tried:
@JsonFormat(pattern = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'", timezone ="UTC")
private LocalDateTime dateTime;
Zon the end means UTC. Delete the quote marks from around the'Z'. Then parse as aInstantorOffsetDateTimeto represent a moment. ALocalDateTimeby definition cannot represent a moment because it purposely lacks any concept of time zone or offset-from-UTC. - Basil BourqueZmeans UTC, not a full time zone. SoZonedDateTimeis not appropriate.Instantis the class you need:Instant.parse( "2018-11-28T15:24:00.000Z" ). Sorry, cannot help you with the Jackson aspect. Have you searched Stack Overflow? Date-time access with Jackson has been asked and answered many times already. - Basil BourqueDateinstead ofLocalDateTime@cvdr - Deadpool