1
我使用Jersey作爲Jackson作爲JSON提供程序。我能夠將ZonedDateTime
序列化爲JSON,但是當我想要反序列化時,它會給我錯誤,如下所示。無法使用Jackson反序列化ZonedDateTime使用Jackson
你能幫我告訴確切的配置需要得到這個反序列化工作。
所致:com.fasterxml.jackson.databind.JsonMappingException:00::不能從字符串值('2016-01-21T21實例化類型[簡單類型,類java.time.ZonedDateTime]的值00Z 「);無單String構造/工廠方法
我的映射配置如下:
@Provider
public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper> {
private final ObjectMapper MAPPER;
public ObjectMapperContextResolver() {
MAPPER = new ObjectMapper();
//This would add JSR310 (Datetime) support while converting date to JSON using JAXRS service
MAPPER.registerModule(new JavaTimeModule());
//Below line would disable use of timestamps (numbers),
//and instead use a [ISO-8601 ]-compliant notation, which gets output as something like: "1970-01-01T00:00:00.000+0000".
MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}
@Override
public ObjectMapper getContext(Class<?> type) {
return MAPPER;
}
}