Jackson 使用时间戳字段反序列化 JSON
2022-09-02 12:22:07
我有这样的字符串:
{
"debug":"false",
"switchTime":"2017-04-12 17:04:42.896026"
}
我试图以这种方式获取对象:
new ObjectMapper().readValue(string, MyObject.class);
和 MyObject 类:
class MyObject {
private Boolean debug;
private Timestamp switchTime;
//...getters, setters, constructors
}
我有这样的例外:
com.fasterxml.jackson.databind.exc.InvalidFormatException:
Can not deserialize value of type java.sql.Timestamp from String
"2017-04-12 17:04:42.896026": not a valid representation (error:
Failed to parse Date value '2017-04-12 17:04:42.896026':
Can not parse date "2017-04-12 17:04:42.896026Z": while it seems
to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSS'Z'',
parsing fails (leniency? null)) at [Source:
{"debug":"false", "switchTime":"2017-04-12 17:04:42.896026"};
我不明白为什么...如果我在调试模式下使用Timestamp.valueOf()与“2017-04-12 17:04:42.896026” - 我有成功