Removed ThreadLocal for activeJsonAdapterClasses
This commit is contained in:
parent
45511fdd15
commit
943c674276
@ -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,26 +86,23 @@ public final class JsonAdapterAnnotationTypeAdapterFactory implements TypeAdapte
|
|||||||
|
|
||||||
TypeAdapter<?> typeAdapter;
|
TypeAdapter<?> typeAdapter;
|
||||||
if (isTypeAdapter || isJsonSerializer || isJsonDeserializer) {
|
if (isTypeAdapter || isJsonSerializer || isJsonDeserializer) {
|
||||||
Map<Class, TypeAdapter> adapters = activeJsonAdapterClasses.get();
|
if (isTypeAdapter) {
|
||||||
typeAdapter = adapters.get(value);
|
Class<TypeAdapter<?>> typeAdapterClass = (Class<TypeAdapter<?>>) value;
|
||||||
if (typeAdapter == null) {
|
typeAdapter = constructorConstructor.get(TypeToken.get(typeAdapterClass)).construct();
|
||||||
if (isTypeAdapter) {
|
} else if (isJsonSerializer || isJsonDeserializer) {
|
||||||
Class<TypeAdapter<?>> typeAdapterClass = (Class<TypeAdapter<?>>) value;
|
JsonSerializer serializer = null;
|
||||||
typeAdapter = constructorConstructor.get(TypeToken.get(typeAdapterClass)).construct();
|
if (isJsonSerializer) {
|
||||||
} else if (isJsonSerializer || isJsonDeserializer) {
|
Class<JsonSerializer<?>> serializerClass = (Class<JsonSerializer<?>>) value;
|
||||||
JsonSerializer serializer = null;
|
serializer = constructorConstructor.get(TypeToken.get(serializerClass)).construct();
|
||||||
if (isJsonSerializer) {
|
|
||||||
Class<JsonSerializer<?>> serializerClass = (Class<JsonSerializer<?>>) value;
|
|
||||||
serializer = constructorConstructor.get(TypeToken.get(serializerClass)).construct();
|
|
||||||
}
|
|
||||||
JsonDeserializer deserializer = null;
|
|
||||||
if (isJsonDeserializer) {
|
|
||||||
Class<JsonDeserializer<?>> deserializerClass = (Class<JsonDeserializer<?>>) value;
|
|
||||||
deserializer = constructorConstructor.get(TypeToken.get(deserializerClass)).construct();
|
|
||||||
}
|
|
||||||
typeAdapter = new TreeTypeAdapter(serializer, deserializer, gson, type, null);
|
|
||||||
}
|
}
|
||||||
adapters.put(value, typeAdapter);
|
JsonDeserializer deserializer = null;
|
||||||
|
if (isJsonDeserializer) {
|
||||||
|
Class<JsonDeserializer<?>> deserializerClass = (Class<JsonDeserializer<?>>) value;
|
||||||
|
deserializer = constructorConstructor.get(TypeToken.get(deserializerClass)).construct();
|
||||||
|
}
|
||||||
|
typeAdapter = new TreeTypeAdapter(serializer, deserializer, gson, type, null);
|
||||||
|
} else {
|
||||||
|
typeAdapter = null;
|
||||||
}
|
}
|
||||||
} else if (TypeAdapterFactory.class.isAssignableFrom(value)) {
|
} else if (TypeAdapterFactory.class.isAssignableFrom(value)) {
|
||||||
TypeAdapterFactory factory = getTypeAdapterFactory(annotation, constructorConstructor);
|
TypeAdapterFactory factory = getTypeAdapterFactory(annotation, constructorConstructor);
|
||||||
|
Loading…
Reference in New Issue
Block a user