We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
自定义反序列化,偶尔成功一次,大部分情况执行时异常:
Caused by: java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.alibaba.fastjson2.reader.FieldReaderObject.accept(FieldReaderObject.java:264)
java sdk: OpenJDK 1.8.0_281 fastjson: 2.0.21
定义
@Data public class CallInfo { private String phoneNum; @JSONField(deserializeUsing = JsonDeserializer.class) private Map<String, Object> varDefine; @JSONField(deserializeUsing = TagDeserializer.class) private List<Tag> tagSession; }
@Data public class Tag { private String tagId; private String tagName; }
public class JsonDeserializer implements ObjectReader<Map<String, Object>> { @Override public Map<String, Object> readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) { String value = jsonReader.readString(); return JSONObject.parseObject(value); } }
public class TagDeserializer implements ObjectReader<List<Tag>> { @Override public List<Tag> readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) { String value = jsonReader.readString(); return JSON.parseArray(value, Tag.class); } }
使用
public static void main(String[] args) { Map<String, String> map = new HashMap<>(); map.put("phoneNum", "1"); map.put("varDefine", "{\"success\":\"yes\"}"); map.put("tagSession", "[{\"tagId\":\"6908494829\",\"tagName\":\"不是本人\"}]"); CallInfo callInfo = JSON.parseObject(JSON.toJSONString(map), CallInfo.class); }
Exception in thread "main" com.alibaba.fastjson2.JSONException: read field 'CallInfo.getVarDefine, offset 117, character }, line 1, column 118, fastjson-version 2.0.21 {"phoneNum":"1","tagSession":"[{\"tagId\":\"6908494829\",\"tagName\":\"不是本人\"}]","varDefine":"{\"success\":\"yes\"}"} at com.alibaba.fastjson2.reader.FieldReaderObject.readFieldValue(FieldReaderObject.java:162) at com.alibaba.fastjson2.reader.ObjectReader3.readObject(ObjectReader3.java:337) at com.alibaba.fastjson2.JSON.parseObject(JSON.java:601) at Test.main(Test.java:20) Caused by: com.alibaba.fastjson2.JSONException: set varDefine error at com.alibaba.fastjson2.reader.FieldReaderObject.accept(FieldReaderObject.java:268) at com.alibaba.fastjson2.reader.FieldReaderObject.readFieldValue(FieldReaderObject.java:147) ... 3 more Caused by: java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.alibaba.fastjson2.reader.FieldReaderObject.accept(FieldReaderObject.java:264) ... 4 more
The text was updated successfully, but these errors were encountered:
fix JSONField#deserializeUsing on Field, for issue #1249
e0b4a91
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.26-SNAPSHOT/ 问题已经修复,请帮忙用2.0.26-SNAPSHOT版本验证
Sorry, something went wrong.
https://github.com/alibaba/fastjson2/releases/tag/2.0.26 问题已修复,请用新版本
No branches or pull requests
问题描述
自定义反序列化,偶尔成功一次,大部分情况执行时异常:
环境信息
java sdk: OpenJDK 1.8.0_281
fastjson: 2.0.21
重现步骤
定义
使用
相关日志输出
The text was updated successfully, but these errors were encountered: