LocalDateTime从任何JSON字符串值对象。
您有几种选择。您可以创建和注册自己的
JsonDeserializer使用方法
LocalDateTime#parse。
class ParseDeserializer extends StdDeserializer<LocalDateTime> { public ParseDeserializer() { super(LocalDateTime.class); } @Override public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { return LocalDateTime.parse(p.getValueAsString()); // or overloaded with an appropriate format }}...@JsonSerialize(using = ToStringSerializer.class)@JsonDeserialize(using = ParseDeserializer.class)private LocalDateTime initiationDate;
或者你也可以添加杰克逊的
java.time延伸到类路径中并注册相应的
Module与你的
ObjectMapper。
objectMapper.registerModule(new JavaTimeModule());
让杰克逊为您做转换。在内部,这
LocalDateTime#parse与一种标准格式一起使用。幸运的是,它支持像
2016-05-11T17:32:20.897
盒子外面。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)