Is Default serialization format of Date has changed with recent Spring boot versions/Jackson Versions?

Viewed 2643

I am in the process of updating the SpringBoot version to 2.3.1.RELEASE from 2.2.2.RELEASE. Suddenly all date format of all my API responses has changed(In the timezone representation section).

From +0000 to +00:00

"timestamp": "2020-05-19T05:46:49.469+0000" -  2.2.2.RELEASE

"timestamp": "2020-06-30T09:55:23.014+00:00" - 2.3.1.RELEASE

This is my Simple POJO: I have not added any @JsonFortmat configuration for the date field.


@NoArgsConstructor
@AllArgsConstructor
@Getter
public class BuildInfo{
    private String message;
    private Date timestamp;
}

and my controller method

    @GetMapping(value = "/buildinfo", produces = "application/json")
    ResponseEntity<BuildInfo> getBuildInfo();

I have not added any serialization/ deserialization logic and I have developed only with SpringBoot's default behavior. I am trying to search any release document regarding this change, but could not find any.

Below changes, I can perform to adapt these changes

  1. Using @JsonFormat annotation with customized pattern in every date field(but I cannot do it as this is client library)

       @JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSSZ")
       private Date timestamp;
    
  2. Injecting Jackson2ObjectMapperBuilderCustomizer in application level.

 @Bean
 public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
     return builder -> builder.simpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
 }

But I would like to narrow down the root cause for the format change? starting from which version of Jackson/Spring libraries?

3 Answers

You can also use the following Spring Boot property to format your JSON dates: spring.jackson.date-format. Note this only works on java.util.Date and java.util.Calendar objects.

Related