Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants