Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

toJavaObject 不会触发JSONField #1727

Open
aqqwiyth opened this issue Feb 1, 2018 · 1 comment
Open

toJavaObject 不会触发JSONField #1727

aqqwiyth opened this issue Feb 1, 2018 · 1 comment
Labels
Milestone

Comments

@aqqwiyth
Copy link

aqqwiyth commented Feb 1, 2018

        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

@aqqwiyth
Copy link
Author

aqqwiyth commented Feb 1, 2018

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

@wenshao wenshao added this to the 1.2.46 milestone Feb 1, 2018
@wenshao wenshao added the bug label Feb 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants