0

I am using spring boot to create a spring data rest application. I want to use ISO 8601 for serializing/deserializing OffsetDateTimes. I have the following in my @Configuration.

@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder() {
    Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    builder.indentOutput(false).dateFormat(ISO8601DateFormat.getDateTimeInstance());
    return builder;
}

This works for older Date objects, but does not work with OffsetDateTime in Java 8. Is there a standard solution to this, or do I need to write my own JsonSerializers (likely extended from StdScalarSerializer) and add the following:

builder
  .deserializerByType(OffsetDateTime.class, myCustomOffsetDateTimeDeserializer)
  .serializerByType(OffsetDateTime.class, myCustomOffsetDateTimeSerializer)

I feel like there must be some standard serializers/deserializers out there for these objects that I'm missing. Are there?

Daniel Moses
  • 5,872
  • 26
  • 39
  • 1
    I think http://stackoverflow.com/questions/27952472/serialize-deserialize-java-8-java-time-with-jackson-json-mapper provides the solution to this question. – Erik Gillespie Apr 21 '15 at 17:10
  • 1
    @ErikGillespie Thanks. I must have searched for all the wrong things. I put the dependency in my project and it's working fine now. – Daniel Moses Apr 21 '15 at 17:20

0 Answers0