jackson annotations being ignored

前端 未结 2 1484
梦如初夏
梦如初夏 2021-01-03 00:35

I\'m trying to use Jackson annotations to re-name some of the json labels produced during serialization. The annotations all compile fine, and when I run, the Jackson seria

2条回答
  •  渐次进展
    2021-01-03 00:44

    Just in case that somebody hits a similiar problem where only @JsonFormat gets ignored:

    Consider that in Spring Boot + Java 8 context the processing of LocalDateTime may experience troubles. Instead of following dependency:

     compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8'
    

    You should use:

     compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310'
    

    Furthermore, when you create your Jackson ObjectMapper you need to register the implementation which treats LocalDateTime correctly:

     json = new ObjectMapper().findAndRegisterModules().writeValueAsString(entity);
     new ObjectMapper().findAndRegisterModules().readValue(json, entity.getClass());
    

提交回复
热议问题