Skip to content

Commit fcda248

Browse files
committed
gson: move nulls to @inline container
The inner value in an `@Inline` record shall never be null, only the outer container.
1 parent ece4f82 commit fcda248

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

jmap-gson/src/main/java/com/audriga/jmap/gson/InlineRecordAdapterFactory.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,18 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
4848
return new TypeAdapter<>() {
4949
@Override
5050
public void write(JsonWriter out, T value) throws IOException {
51-
adapter.write(out, GsonUtils.invoke(accessor, value));
51+
if (value == null) {
52+
out.nullValue();
53+
} else {
54+
adapter.write(out, GsonUtils.invoke(accessor, value));
55+
}
5256
}
5357

5458
@Override
5559
@SuppressWarnings("unchecked")
5660
public T read(JsonReader in) throws IOException {
57-
return (T) GsonUtils.invoke(ctor, adapter.read(in));
61+
var read = adapter.read(in);
62+
return read == null ? null : (T) GsonUtils.invoke(ctor, read);
5863
}
5964
};
6065
}

0 commit comments

Comments
 (0)