Skip to content

Commit

Permalink
Fix RuntimeTypeAdapterFactory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
t-oster committed Jun 29, 2022
1 parent ca4b28c commit db02def
Showing 1 changed file with 5 additions and 5 deletions.
Expand Up @@ -16,10 +16,6 @@

package com.google.gson.typeadapters;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand All @@ -30,6 +26,10 @@
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;


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

@Override
public <R> TypeAdapter<R> create(Gson gson, TypeToken<R> type) {
if (type.getRawType() != baseType) {
if (type == null || !baseType.isAssignableFrom(type.getRawType())) {
return null;
}

Expand Down

0 comments on commit db02def

Please sign in to comment.