Skip to content

Commit

Permalink
fix null value field read error on non-default-constructor, for issue a…
Browse files Browse the repository at this point in the history
  • Loading branch information
rowstop committed Feb 4, 2024
1 parent 0bf5235 commit 1dd43ce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ public T readObject(JSONReader jsonReader, Type fieldType, Object fieldName, lon
}
continue;
}

if (jsonReader.nextIfNull()) {
continue;
}
FieldReader fieldReader = getFieldReader(hashCode);
FieldReader paramReader = paramFieldReaderMap.get(hashCode);
if (paramReader != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,33 @@ void test() throws JSONException {
JSONAssert.assertEquals(json, JSON.toJSONString(obj, JSONWriter.Feature.WriteNulls), true);
}

@Test
void test2() throws JSONException {
String json = "{\"log_entries\": null,\"test\":[]}";
Obj2 obj = assertDoesNotThrow(
() -> JSON.parseObject(json, Obj2.class)
);
JSONAssert.assertEquals(json, JSON.toJSONString(obj, JSONWriter.Feature.WriteNulls), true);
}

@Getter
@Setter
static class Obj2{
@JsonProperty("log_entries")
private List<LogEntry> logEntries;
private List test;

public Obj2(List<LogEntry> logEntries) {
this.logEntries = logEntries;
}
}

@Getter
@Setter
static class LogEntry{
private String name;
}

@Getter
@Setter
static class Obj{
Expand Down

0 comments on commit 1dd43ce

Please sign in to comment.