【发布时间】:2020-01-09 11:50:53
【问题描述】:
我有一个对象,其中嵌套了一个 Joda DateTime 对象,但我无法对其进行序列化和反序列化。
当我序列化嵌套了 DateTime 的完整对象时,输出看起来与直接序列化 DateTime 对象时大不相同,我的结果如下
new ObjectMapper.writeValueAsString(fullObjectWithDateTime) 为 DateTime 对象生成以下 blob:
{
"dateTime": {
"weekOfWeekyear": 34,
"weekyear": 2019,
"yearOfEra": 2019,
"yearOfCentury": 19,
"centuryOfEra": 20,
"secondOfDay": 4530,
"minuteOfDay": 75,
"millisOfDay": 4530777,
"monthOfYear": 8,
"hourOfDay": 1,
"minuteOfHour": 15,
"secondOfMinute": 30,
"millisOfSecond": 777,
"year": 2019,
"dayOfMonth": 21,
"dayOfWeek": 3,
"era": 1,
"dayOfYear": 233,
"millis": 1566350130777,
"chronology": {
"zone": {
"fixed": true,
"id": "UTC"
}
},
"zone": {
"fixed": true,
"id": "UTC"
},
"afterNow": false,
"beforeNow": true,
"equalNow": false
}
}
ObjectMapper.writeValueAsString(fullObjectWithDateTime.getDateTime())
产生:
"2019-08-21T01:15:30.777Z"
当我尝试反序列化由 ObjectMapper.writeValueAsString(fullObjectWithDateTime) 生成的对象时出现错误,其中显示
'com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of org.joda.time.DateTime out of START_OBJECT token'
【问题讨论】:
标签: java json datetime jackson jodatime