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")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void write(JsonWriter writer, T value) throws IOException {
|
public void write(JsonWriter writer, T value) throws IOException {
|
||||||
|
TypeAdapter t = delegate;
|
||||||
|
if (delegate instanceof ReflectiveTypeAdapter) {
|
||||||
Type runtimeType = Reflection.getRuntimeTypeIfMoreSpecific(type, value);
|
Type runtimeType = Reflection.getRuntimeTypeIfMoreSpecific(type, value);
|
||||||
TypeAdapter t = runtimeType != type ?
|
if (runtimeType != type) {
|
||||||
context.getAdapter(TypeToken.get(runtimeType)) : delegate;
|
t = context.getAdapter(TypeToken.get(runtimeType));
|
||||||
|
}
|
||||||
|
}
|
||||||
t.write(writer, value);
|
t.write(writer, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user