String jsonString = "{\"gmtCreate\":\"20180131214157805-0800\"}";
JSONObject.parseObject(jsonString, XX.class); //正常解析
JSONObject.toJavaObject(JSON.parseObject(jsonString), XX.class);
@JSONField(format="yyyyMMddHHmmssSSSZ")
private Date gmtCreate;
Caused by: com.alibaba.fastjson.JSONException: can not cast to Date, value : 20180131214157805-0800
at com.alibaba.fastjson.util.TypeUtils.castToDate(TypeUtils.java:326)
at com.alibaba.fastjson.util.TypeUtils.cast(TypeUtils.java:746)
at com.alibaba.fastjson.util.TypeUtils.cast(TypeUtils.java:846)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.createInstance(JavaBeanDeserializer.java:1159)
at com.alibaba.fastjson.util.TypeUtils.castToJavaBean(TypeUtils.java:1034)
... 8 more
1条答案
按热度按时间b09cbbtk1#
JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss" 没有命中format,代码进一步进行了long转换