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

[QUESTION]JSONObject.to()出现空指针异常 #1034

Closed
18681466471 opened this issue Dec 26, 2022 · 2 comments
Closed

[QUESTION]JSONObject.to()出现空指针异常 #1034

18681466471 opened this issue Dec 26, 2022 · 2 comments
Labels
fixed question Further information is requested
Milestone

Comments

@18681466471
Copy link

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<T> {
    @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)

@18681466471 18681466471 added the question Further information is requested label Dec 26, 2022
wenshao added a commit that referenced this issue Dec 27, 2022
@wenshao
Copy link
Member

wenshao commented Dec 27, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.22-SNAPSHOT/
问题已经修复,请用2.0.22-SNAPSHOT版本验证,2.0.22版本在元旦期间发布

@wenshao wenshao added the fixed label Dec 27, 2022
@wenshao wenshao added this to the 2.0.22 milestone Dec 27, 2022
@wenshao
Copy link
Member

wenshao commented Dec 31, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.22
问题已修复,请用新版本

@wenshao wenshao closed this as completed Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants