Top Description Inners Fields Constructors Methods
com.google.gson.internal.bind

public final Class TreeTypeAdapter<T>

extends SerializationDelegatingTypeAdapter<T>
Class Inheritance
Imports
com.google.gson.Gson, .JsonDeserializationContext, .JsonDeserializer, .JsonElement, .JsonParseException, .JsonSerializationContext, .JsonSerializer, .TypeAdapter, .TypeAdapterFactory, com.google.gson.internal.Streams, com.google.gson.reflect.TypeToken, com.google.gson.stream.JsonReader, .JsonWriter, java.io.IOException, java.lang.reflect.Type, java.util.Objects

Adapts a Gson 1.x tree-style adapter as a streaming TypeAdapter. Since the tree adapter may be serialization-only or deserialization-only, this class has a facility to look up a delegate type adapter on demand.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class

Field Summary

Modifier and TypeField and Description
private final TreeTypeAdapter<T>.GsonContextImpl
private volatile TypeAdapter<T>
delegate

The delegate is lazily created because it may not be needed, and creating it may fail.

private final JsonDeserializer<T>
pack-priv final Gson
private final boolean
private final JsonSerializer<T>
private final TypeAdapterFactory
skipPastForGetDelegateAdapter

Only intended as skipPast for Gson#getDelegateAdapter(TypeAdapterFactory, TypeToken), must not be used in any other way.

private final TypeToken<T>

Constructor Summary

AccessConstructor and Description
public
TreeTypeAdapter(JsonSerializer<T> serializer, JsonDeserializer<T> deserializer, Gson gson, TypeToken<T> typeToken, TypeAdapterFactory skipPast, boolean nullSafe)

public
TreeTypeAdapter(JsonSerializer<T> serializer, JsonDeserializer<T> deserializer, Gson gson, TypeToken<T> typeToken, TypeAdapterFactory skipPast)

Method Summary

Modifier and TypeMethod and Description
private TypeAdapter<T>
public TypeAdapter<T>
getSerializationDelegate()

Implements abstract com.google.gson.internal.bind.SerializationDelegatingTypeAdapter.getSerializationDelegate.

Returns the type adapter which is used for serialization.

public static TypeAdapterFactory
newFactory(TypeToken<?> exactType, Object typeAdapter)

Returns a new factory that will match each type against exactType.

public static TypeAdapterFactory
newFactoryWithMatchRawType(TypeToken<?> exactType, Object typeAdapter)

Returns a new factory that will match each type and its raw type against exactType.

public static TypeAdapterFactory
newTypeHierarchyFactory(Class<?> hierarchyType, Object typeAdapter)

Returns a new factory that will match each type's raw type for assignability to hierarchyType.

public T
read(JsonReader in)

Implements abstract com.google.gson.TypeAdapter.read.

Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object.

public void
write(JsonWriter out, T value)

Implements abstract com.google.gson.TypeAdapter.write.

Writes one JSON value (an array, object, string, number, boolean or null) for value.

Field Detail

contextback to summary
private final TreeTypeAdapter<T>.GsonContextImpl context
delegateback to summary
private volatile TypeAdapter<T> delegate

The delegate is lazily created because it may not be needed, and creating it may fail. Field has to be volatile because Gson guarantees to be thread-safe.

deserializerback to summary
private final JsonDeserializer<T> deserializer
gsonback to summary
pack-priv final Gson gson
nullSafeback to summary
private final boolean nullSafe
serializerback to summary
private final JsonSerializer<T> serializer
skipPastForGetDelegateAdapterback to summary
private final TypeAdapterFactory skipPastForGetDelegateAdapter

Only intended as skipPast for Gson#getDelegateAdapter(TypeAdapterFactory, TypeToken), must not be used in any other way.

typeTokenback to summary
private final TypeToken<T> typeToken

Constructor Detail

TreeTypeAdapterback to summary
public TreeTypeAdapter(JsonSerializer<T> serializer, JsonDeserializer<T> deserializer, Gson gson, TypeToken<T> typeToken, TypeAdapterFactory skipPast, boolean nullSafe)
TreeTypeAdapterback to summary
public TreeTypeAdapter(JsonSerializer<T> serializer, JsonDeserializer<T> deserializer, Gson gson, TypeToken<T> typeToken, TypeAdapterFactory skipPast)

Method Detail

delegateback to summary
private TypeAdapter<T> delegate()
getSerializationDelegateback to summary
public TypeAdapter<T> getSerializationDelegate()

Implements abstract com.google.gson.internal.bind.SerializationDelegatingTypeAdapter.getSerializationDelegate.

Returns the type adapter which is used for serialization. Returns this if this TreeTypeAdapter has a serializer; otherwise returns the delegate.

Annotations
@Override
newFactoryback to summary
public static TypeAdapterFactory newFactory(TypeToken<?> exactType, Object typeAdapter)

Returns a new factory that will match each type against exactType.

newFactoryWithMatchRawTypeback to summary
public static TypeAdapterFactory newFactoryWithMatchRawType(TypeToken<?> exactType, Object typeAdapter)

Returns a new factory that will match each type and its raw type against exactType.

newTypeHierarchyFactoryback to summary
public static TypeAdapterFactory newTypeHierarchyFactory(Class<?> hierarchyType, Object typeAdapter)

Returns a new factory that will match each type's raw type for assignability to hierarchyType.

readback to summary
public T read(JsonReader in) throws IOException

Implements abstract com.google.gson.TypeAdapter.read.

Doc from com.google.gson.TypeAdapter.read.

Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object. Returns the converted object.

Annotations
@Override
writeback to summary
public void write(JsonWriter out, T value) throws IOException

Implements abstract com.google.gson.TypeAdapter.write.

Doc from com.google.gson.TypeAdapter.write.

Writes one JSON value (an array, object, string, number, boolean or null) for value.

Annotations
@Override
com.google.gson.internal.bind back to summary

private final Class TreeTypeAdapter.GsonContextImpl

extends Object
implements JsonSerializationContext, JsonDeserializationContext
Class Inheritance
  • java.lang.Object
  • com.google.gson.internal.bind.TreeTypeAdapter.GsonContextImpl
All Implemented Interfaces
com.google.gson.JsonDeserializationContext, com.google.gson.JsonSerializationContext

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public <R> R
deserialize(JsonElement json, Type typeOfT)

Implements com.google.gson.JsonDeserializationContext.deserialize.

Invokes default deserialization on the specified object.

public JsonElement
serialize(Object src)

Implements com.google.gson.JsonSerializationContext.serialize.

Invokes default serialization on the specified object.

public JsonElement
serialize(Object src, Type typeOfSrc)

Implements com.google.gson.JsonSerializationContext.serialize.

Invokes default serialization on the specified object passing the specific type information.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

GsonContextImplback to summary
private GsonContextImpl()

Method Detail

deserializeback to summary
public <R> R deserialize(JsonElement json, Type typeOfT) throws JsonParseException

Implements com.google.gson.JsonDeserializationContext.deserialize.

Doc from com.google.gson.JsonDeserializationContext.deserialize.

Invokes default deserialization on the specified object. It should never be invoked on the element received as a parameter of the JsonDeserializer#deserialize(JsonElement, Type, JsonDeserializationContext) method. Doing so will result in an infinite loop since Gson will in-turn call the custom deserializer again.

Annotations
@Override
@SuppressWarnings:TypeParameterUnusedInFormals
Exceptions
JsonParseException:
if the parse tree does not contain expected data.
serializeback to summary
public JsonElement serialize(Object src)

Implements com.google.gson.JsonSerializationContext.serialize.

Doc from com.google.gson.JsonSerializationContext.serialize.

Invokes default serialization on the specified object.

Annotations
@Override
serializeback to summary
public JsonElement serialize(Object src, Type typeOfSrc)

Implements com.google.gson.JsonSerializationContext.serialize.

Doc from com.google.gson.JsonSerializationContext.serialize.

Invokes default serialization on the specified object passing the specific type information. It should never be invoked on the element received as a parameter of the JsonSerializer#serialize(Object, Type, JsonSerializationContext) method. Doing so will result in an infinite loop since Gson will in-turn call the custom serializer again.

Annotations
@Override
com.google.gson.internal.bind back to summary

private final Class TreeTypeAdapter.SingleTypeFactory

extends Object
implements TypeAdapterFactory
Class Inheritance
  • java.lang.Object
  • com.google.gson.internal.bind.TreeTypeAdapter.SingleTypeFactory
All Implemented Interfaces
com.google.gson.TypeAdapterFactory

Field Summary

Modifier and TypeField and Description
private final JsonDeserializer<?>
private final TypeToken<?>
private final Class<?>
private final boolean
private final JsonSerializer<?>

Constructor Summary

AccessConstructor and Description
pack-priv
SingleTypeFactory(Object typeAdapter, TypeToken<?> exactType, boolean matchRawType, Class<?> hierarchyType)

Method Summary

Modifier and TypeMethod and Description
public <T> TypeAdapter<T>
create(Gson gson, TypeToken<T> type)

Implements com.google.gson.TypeAdapterFactory.create.

Returns a type adapter for type, or null if this factory doesn't support type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

deserializerback to summary
private final JsonDeserializer<?> deserializer
exactTypeback to summary
private final TypeToken<?> exactType
hierarchyTypeback to summary
private final Class<?> hierarchyType
matchRawTypeback to summary
private final boolean matchRawType
serializerback to summary
private final JsonSerializer<?> serializer

Constructor Detail

SingleTypeFactoryback to summary
pack-priv SingleTypeFactory(Object typeAdapter, TypeToken<?> exactType, boolean matchRawType, Class<?> hierarchyType)

Method Detail

createback to summary
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type)

Implements com.google.gson.TypeAdapterFactory.create.

Doc from com.google.gson.TypeAdapterFactory.create.

Returns a type adapter for type, or null if this factory doesn't support type.

Annotations
@SuppressWarnings:unchecked
@Override