fastjson toJavaObject 不会触发JSONField

ff29svar  于 2021-11-27  发布在  Java
关注(0)|答案(1)|浏览(1722)
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

b09cbbtk

b09cbbtk1#

JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss" 没有命中format,代码进一步进行了long转换

相关问题