JSONObject.to()出现空指针异常
public static void main(String[] args) { String json = "{"PARAMETER":{"SSRC":[null,15,null,null,null,null,null,null,null,null,null,null,null],"RUN":124}}"; Param<?> param = JSON.parseObject(json, Param.class); JSONObject jsonBody = (JSONObject) param.getParameter(); TypeReference typeReference = new TypeReference() { }; Object to = jsonBody.to(typeReference.getType()); System.out.println(to); } @getter @Setter static class Test { @JSONField(name = "RUN") private Integer run; @JSONField(name = "SSRC") private List ssrc; }
@Getter @Setter static class Param { @JSONField(name = "PARAMETER") private T parameter; }
fastjson2: 2.0.12 result is : Caused by: java.lang.NullPointerException at com.alibaba.fastjson2.reader.ObjectReaderImplList.createInstance(ObjectReaderImplList.java:176) at com.alibaba.fastjson2.JSONArray.to(JSONArray.java:939) at com.alibaba.fastjson2.reader.ObjectReader.createInstance(ObjectReader.java:109) at com.alibaba.fastjson2.JSONObject.to(JSONObject.java:1141)
原提问者GitHub用户18681466471
问题已修复,请用新版本 https://github.com/alibaba/fastjson2/releases/tag/2.0.22
原回答者GitHub用户wenshao
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。