Removed ThreadLocal for activeJsonAdapterClasses

This commit is contained in:
Inderjeet Singh 2016-05-31 10:14:24 -07:00 committed by jwilson
parent 45511fdd15
commit 943c674276

View File

@ -36,13 +36,6 @@ import com.google.gson.reflect.TypeToken;
*/ */
public final class JsonAdapterAnnotationTypeAdapterFactory implements TypeAdapterFactory { public final class JsonAdapterAnnotationTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("rawtypes")
private final ThreadLocal<Map<Class, TypeAdapter>> activeJsonAdapterClasses = new ThreadLocal<Map<Class, TypeAdapter>>() {
@Override protected Map<Class, TypeAdapter> initialValue() {
// No need for a thread-safe map since we are using it in a single thread
return new HashMap<Class, TypeAdapter>();
}
};
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private final ThreadLocal<Map<Class, TypeAdapterFactory>> activeJsonAdapterFactories = new ThreadLocal<Map<Class, TypeAdapterFactory>>() { private final ThreadLocal<Map<Class, TypeAdapterFactory>> activeJsonAdapterFactories = new ThreadLocal<Map<Class, TypeAdapterFactory>>() {
@Override protected Map<Class, TypeAdapterFactory> initialValue() { @Override protected Map<Class, TypeAdapterFactory> initialValue() {
@ -93,9 +86,6 @@ public final class JsonAdapterAnnotationTypeAdapterFactory implements TypeAdapte
TypeAdapter<?> typeAdapter; TypeAdapter<?> typeAdapter;
if (isTypeAdapter || isJsonSerializer || isJsonDeserializer) { if (isTypeAdapter || isJsonSerializer || isJsonDeserializer) {
Map<Class, TypeAdapter> adapters = activeJsonAdapterClasses.get();
typeAdapter = adapters.get(value);
if (typeAdapter == null) {
if (isTypeAdapter) { if (isTypeAdapter) {
Class<TypeAdapter<?>> typeAdapterClass = (Class<TypeAdapter<?>>) value; Class<TypeAdapter<?>> typeAdapterClass = (Class<TypeAdapter<?>>) value;
typeAdapter = constructorConstructor.get(TypeToken.get(typeAdapterClass)).construct(); typeAdapter = constructorConstructor.get(TypeToken.get(typeAdapterClass)).construct();
@ -111,8 +101,8 @@ public final class JsonAdapterAnnotationTypeAdapterFactory implements TypeAdapte
deserializer = constructorConstructor.get(TypeToken.get(deserializerClass)).construct(); deserializer = constructorConstructor.get(TypeToken.get(deserializerClass)).construct();
} }
typeAdapter = new TreeTypeAdapter(serializer, deserializer, gson, type, null); typeAdapter = new TreeTypeAdapter(serializer, deserializer, gson, type, null);
} } else {
adapters.put(value, typeAdapter); typeAdapter = null;
} }
} else if (TypeAdapterFactory.class.isAssignableFrom(value)) { } else if (TypeAdapterFactory.class.isAssignableFrom(value)) {
TypeAdapterFactory factory = getTypeAdapterFactory(annotation, constructorConstructor); TypeAdapterFactory factory = getTypeAdapterFactory(annotation, constructorConstructor);