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