serialize/deserialize java 8 java.time with Jackson JSON mapper

后端 未结 17 1332
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 15:56

How do I use Jackson JSON mapper with Java 8 LocalDateTime?

org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple t

17条回答
  •  暖寄归人
    2020-11-22 16:35

    This maven dependency will solve your problem:

    
        com.fasterxml.jackson.datatype
        jackson-datatype-jsr310
        2.6.5
    
    

    One thing I've struggled is that for ZonedDateTime timezone being changed to GMT during deserialization. Turned out, that by default jackson replaces it with one from context.. To keep zone one must disable this 'feature'

    Jackson2ObjectMapperBuilder.json()
        .featuresToDisable(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)
    

提交回复
热议问题