Recently I was trying to serialize a Java object into json using ObjectMapper but encountered the following exception
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.ZonedDateTime` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
The reason was that Java time module is not supported by default and it does not work just by adding maven dependency. The following code worked for me.
objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
No comments:
Post a Comment