Restored this behavior:
If a type adapter is registered for a base class, then a field of that type is serialized with the type adapter instead of using the run-time type. This fixes: CustomSerializerTest.testBaseClassSerializerInvokedForBaseClassFieldsHoldingSubClassInstances
This commit is contained in:
parent
ad5ff0f2d9
commit
f7121ad87d
@ -42,9 +42,13 @@ final class TypeAdapterRuntimeTypeWrapper<T> extends TypeAdapter<T> {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void write(JsonWriter writer, T value) throws IOException {
|
||||
Type runtimeType = Reflection.getRuntimeTypeIfMoreSpecific(type, value);
|
||||
TypeAdapter t = runtimeType != type ?
|
||||
context.getAdapter(TypeToken.get(runtimeType)) : delegate;
|
||||
TypeAdapter t = delegate;
|
||||
if (delegate instanceof ReflectiveTypeAdapter) {
|
||||
Type runtimeType = Reflection.getRuntimeTypeIfMoreSpecific(type, value);
|
||||
if (runtimeType != type) {
|
||||
t = context.getAdapter(TypeToken.get(runtimeType));
|
||||
}
|
||||
}
|
||||
t.write(writer, value);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user