Package com.google.gson.graph
Class GraphAdapterBuilder.Factory
- java.lang.Object
-
- com.google.gson.graph.GraphAdapterBuilder.Factory
-
- All Implemented Interfaces:
InstanceCreator<java.lang.Object>,TypeAdapterFactory
- Enclosing class:
- GraphAdapterBuilder
static class GraphAdapterBuilder.Factory extends java.lang.Object implements TypeAdapterFactory, InstanceCreator<java.lang.Object>
A factory that creates type adapters capable of serializing and deserializing object graphs.This factory implements both
TypeAdapterFactoryandInstanceCreatorinterfaces. It is responsible for handling cyclic references by assigning unique names to objects and managing a graph during both serialization and deserialization.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ThreadLocal<GraphAdapterBuilder.Graph>graphThreadLocalprivate java.util.Map<java.lang.reflect.Type,InstanceCreator<?>>instanceCreators
-
Constructor Summary
Constructors Constructor Description Factory(java.util.Map<java.lang.reflect.Type,InstanceCreator<?>> instanceCreators)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TypeAdapter<T>create(Gson gson, TypeToken<T> type)Returns a type adapter fortype, or null if this factory doesn't supporttype.java.lang.ObjectcreateInstance(java.lang.reflect.Type type)Hook for the graph adapter to get a reference to a deserialized value before that value is fully populated.
-
-
-
Field Detail
-
instanceCreators
private final java.util.Map<java.lang.reflect.Type,InstanceCreator<?>> instanceCreators
-
graphThreadLocal
private final java.lang.ThreadLocal<GraphAdapterBuilder.Graph> graphThreadLocal
-
-
Constructor Detail
-
Factory
Factory(java.util.Map<java.lang.reflect.Type,InstanceCreator<?>> instanceCreators)
-
-
Method Detail
-
create
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)
Description copied from interface:TypeAdapterFactoryReturns a type adapter fortype, or null if this factory doesn't supporttype.- Specified by:
createin interfaceTypeAdapterFactory
-
createInstance
public java.lang.Object createInstance(java.lang.reflect.Type type)
Hook for the graph adapter to get a reference to a deserialized value before that value is fully populated. This is useful to deserialize values that directly or indirectly reference themselves: we can hand out an instance before read() returns.Gson should only ever call this method when we're expecting it to; that is only when we've called back into Gson to deserialize a tree.
- Specified by:
createInstancein interfaceInstanceCreator<java.lang.Object>- Parameters:
type- the parameterized T represented as aType.- Returns:
- a default object instance of type T.
-
-