Skip to content

Commit db02def

Browse files
committed
Fix RuntimeTypeAdapterFactory
Trying to use this class as is results in the type-property not being serialized into the JSON, thus it is not present on deserialization. The fix from #712 (comment) works. No idea why this is not merged yet.
1 parent ca4b28c commit db02def

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717
package com.google.gson.typeadapters;
1818

19-
import java.io.IOException;
20-
import java.util.LinkedHashMap;
21-
import java.util.Map;
22-
2319
import com.google.gson.Gson;
2420
import com.google.gson.JsonElement;
2521
import com.google.gson.JsonObject;
@@ -30,6 +26,10 @@
3026
import com.google.gson.reflect.TypeToken;
3127
import com.google.gson.stream.JsonReader;
3228
import com.google.gson.stream.JsonWriter;
29+
import java.io.IOException;
30+
import java.util.LinkedHashMap;
31+
import java.util.Map;
32+
3333

3434
/**
3535
* Adapts values whose runtime type may differ from their declaration type. This
@@ -205,7 +205,7 @@ public RuntimeTypeAdapterFactory<T> registerSubtype(Class<? extends T> type) {
205205

206206
@Override
207207
public <R> TypeAdapter<R> create(Gson gson, TypeToken<R> type) {
208-
if (type.getRawType() != baseType) {
208+
if (type == null || !baseType.isAssignableFrom(type.getRawType())) {
209209
return null;
210210
}
211211

0 commit comments

Comments
 (0)