From 4f45e7462cb883bd046ac3f40a3073156b68a897 Mon Sep 17 00:00:00 2001 From: Thomas Oster Date: Mon, 27 Jun 2022 13:37:01 +0200 Subject: [PATCH] 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 https://github.com/google/gson/issues/712#issuecomment-148955110 works. No idea why this is not merged yet. --- .../com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java b/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java index 3e8aebcf60..840db7d172 100644 --- a/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java +++ b/extras/src/main/java/com/google/gson/typeadapters/RuntimeTypeAdapterFactory.java @@ -205,7 +205,7 @@ public RuntimeTypeAdapterFactory registerSubtype(Class type) { @Override public TypeAdapter create(Gson gson, TypeToken type) { - if (type.getRawType() != baseType) { + if (null == type || !baseType.isAssignableFrom(type.getRawType())) { return null; }