Json Jackson,将字符串反序列化为日期
我有以下JSON属性:Json Jackson,将字符串反序列化为日期,json,jackson,resttemplate,Json,Jackson,Resttemplate,我有以下JSON属性: "created_at":"2017-12-08T10:56:01.000Z" @JsonProperty("created_at") @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-ddTHH:mm:ss.SSSZ") private java.util.Date createdAt; 我想使用Jackson将JSON文档反序列化为以下属性: "created_at":"2017-12-
"created_at":"2017-12-08T10:56:01.000Z"
@JsonProperty("created_at")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-ddTHH:mm:ss.SSSZ")
private java.util.Date createdAt;
我想使用Jackson
将JSON文档反序列化为以下属性:
"created_at":"2017-12-08T10:56:01.000Z"
@JsonProperty("created_at")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-ddTHH:mm:ss.SSSZ")
private java.util.Date createdAt;
但它失败了,但有以下例外:
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.example.domain.Product] and content type [application/json;charset=utf-8]
at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:119)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:986)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:969)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:717)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:671)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:587)
我做错了什么以及如何修复它?问题在于
JsonFormat
的模式
部分
使用“yyyy-MM-dd'T'HH:MM:ss.SSSZ”
代替“yyy-MM-ddTHH:MM:ss.SSSZ”
“yyyy-MM-dd'HH:MM:ss.SSSZ”
“2017-12-08T13:50:07.811+0000”
“yyyy-MM-dd'T'HH:MM:ss.SSS'Z'”
“2017-12-08T13:49:42.128Z”