如何使用Jackson序列化LocalDateTime?
我得到了以下代码:
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
String now = new ObjectMapper().writeValueAsString(new SomeClass(LocalDateTime.now()));
System.out.println(now);
我得到这个:
{“time”:{“hour”:20,“minute”:49,“second”:42,“nano”:99000000,“dayOfYear”:19,“dayOfWeek”:“Thursday”,“month”:“JANUARY”,“dayOfMonth”:19,“year”:2017,“monthValue”:1,“chronology”:{“id”:“ISO”,“calendarType”:“iso8601”}}}
我想实现的是ISO8601中的字符串
2018-19-19T10:43:41Z