title: Formatting Java Time with Spring Boot using JSON
body: <p>I want to implement a custom validator in a Spring Boot v1.5.14.RELEASE app. First I create a custom constraint annotation:</p>
  
  <p>I have this object:</p>
  
  <pre><code>@Getter
  @Setter
  @AllArgsConstructor
  @NoArgsConstructor
  @JsonInclude(JsonInclude.Include.NON_NULL)
  @SuperBuilder
  public class Hotel {
  
      @JsonFormat(pattern = "yyyy-MM-dd")
      private OffsetDateTime interactionDurationStart;
      @JsonFormat(pattern = "yyyy-MM-dd")
      private OffsetDateTime interactionDurationEnd;
  
  }
  </code></pre>
  
  <p>in the yml:</p>
  
  <pre><code>spring:
    jackson:
      mapper:
        DEFAULT_VIEW_INCLUSION: true
      serialization:
        WRITE_DATES_AS_TIMESTAMPS: false
  </code></pre>
  
  <p>and in my configuration file:</p>
  
  <pre><code>@Primary
  @Bean
  public ObjectMapper objectMapper() {
  
      ObjectMapper objectMapper = new ObjectMapper();
      //objectMapper.registerModule(new JavaTimeModule());
      SimpleModule simpleModule = new SimpleModule();
      simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer&lt;OffsetDateTime&gt;() {
          @Override
          public void serialize(OffsetDateTime offsetDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
              jsonGenerator.writeString(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(offsetDateTime));
          }
      });
      objectMapper.registerModule(simpleModule);
  
      return objectMapper;
  }
  </code></pre>
  
  <p>but this is what i see in the API response</p>
  
  <pre><code>"interactionDurationEnd" : {
        "offset" : {
          "totalSeconds" : 7200,
          "id" : "+02:00",
          "rules" : {
            "transitionRules" : [ ],
            "transitions" : [ ],
            "fixedOffset" : true
          }
        },
  </code></pre>