英文:
Issue with mapping timestamp field in json to java.sql.Timestamp
问题
我正在尝试将 JSON 输入传递给 Spring REST 端点。JSON 中有一个字段是:
"timestamp": "2017-04-12 10:12:31.4610"
在领域类中,相应的字段是:
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss.SSSX")
Timestamp timestamp;
但是我在处理该字段时遇到了反序列化问题:
HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.sql.Timestamp` from String "2017-04-12 10:12:31.4610": not a valid representation (error: Failed to parse Date value '2017-04-12 10:12:31.4610': Cannot parse date "2017-04-12 10:12:31.4610": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))
我还尝试了:
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSSX")
Timestamp timestamp;
但是仍然抛出相同的错误。我在这里犯了什么错误?
英文:
I am trying to pass a json input to a spring rest endpoint. JSON has one of the field as:
"timestamp": "2017-04-12 10:12:31.4610"
In domain class, corresponding field is:
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss.SSSX")
Timestamp timestamp;
But I get deserialization issue with this field:
HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.sql.Timestamp` from String "2017-04-12 10:12:31.4610": not a valid representation (error: Failed to parse Date value '2017-04-12 10:12:31.4610': Cannot parse date "2017-04-12 10:12:31.4610": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))
I also tried with:
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss.SSSX")
Timestamp timestamp;
But same error is thrown.
What mistake am I making here?
专注分享java语言的经验与见解,让所有开发者获益!
评论