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:
Inderjeet Singh 2011-08-12 01:59:22 +00:00
parent ad5ff0f2d9
commit f7121ad87d

View File

@ -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);
}
}