class Model {
// ..
@JsonDeserialize(using = LocalDateDeserializer. class)
private LocalDateTime date;
// ..
}
JavaTimeModule module = new JavaTimeModule();
LocalDateTimeDeserializer localDateTimeDeserializer = new
LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a"));
module.addDeserializer(LocalDateTime.class, localDateTimeDeserializer);
Object Mapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modules(module)
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.build();
objectMapper.convertValue(listOFObject, new TypeReference<List<Model>>() {})
在模型类json中 DateString = "02/21/2020 11:00:00 PM"
;
错误->com.fasterxml.jackson.databind.exc.invalidformatexception无法将值“02/21/2020 11:00:00 pm”反序列化为localdatetime
当我试着 LocalDateTime dateTime= LocalDateTime.parse("02/21/2020 11:00:00 PM"
, DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm:ss a"));
它给出了op:-2020-02-21t23:00
我可以知道我错在哪里吗。
暂无答案!
目前还没有任何答案,快来回答吧!