Package com.ibm.cloud.sdk.core.util
Class DiscriminatorBasedTypeAdapterFactory.Adapter<T>
- java.lang.Object
-
- com.google.gson.TypeAdapter<T>
-
- com.ibm.cloud.sdk.core.util.DiscriminatorBasedTypeAdapterFactory.Adapter<T>
-
- Enclosing class:
- DiscriminatorBasedTypeAdapterFactory
public static class DiscriminatorBasedTypeAdapterFactory.Adapter<T> extends com.google.gson.TypeAdapter<T>An adapter for serializing/deserializing instances of type T, where T represents a generated model that defines a discriminator to aid in deserialization. This TypeAdapter will use the cached DiscriminatorMetadata to select the proper Class for the deserialization target.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tread(com.google.gson.stream.JsonReader in)This method is responsible for deserializing a JSON object into an instance of the class identified by the discriminator mapping information.voidwrite(com.google.gson.stream.JsonWriter out, T value)We wouldn't normally expect Gson to call our write() method because we should never actually have instances of a "oneOf" base class (they are implemented as abstract base classes).
-
-
-
Method Detail
-
write
public void write(com.google.gson.stream.JsonWriter out, T value) throws java.io.IOExceptionWe wouldn't normally expect Gson to call our write() method because we should never actually have instances of a "oneOf" base class (they are implemented as abstract base classes). However, in some serialization scenarios, Gson will use the DECLARED type (rather than an object's actual RUNTIME type) when trying to find a suitable TypeAdapter. One scenario where this occurs is where a class contains a field of type List of X, where X is a oneOf base class with a discriminator. So in those cases where we're asked to serialize something, we'll just delegate to a TypeAdapter that's associated with the object's specific runtime type (i.e. the subclass).- Specified by:
writein classcom.google.gson.TypeAdapter<T>- Throws:
java.io.IOException
-
read
public T read(com.google.gson.stream.JsonReader in) throws java.io.IOException
This method is responsible for deserializing a JSON object into an instance of the class identified by the discriminator mapping information. We'll perform the following steps: 1) Do a parse of the JSON object to obtain the JsonElement parse tree. This step produces an intermediate form of the deserialized JSON object and consumes the entire object within the JsonReader. 2) Retrieve the discriminator value from the JsonElement parse tree. 3) Select the proper deserialization target class by looking up the discriminator value in the cached mapping info. 4) Deserialize the JsonElement parse tree into an instance of the selected deserialization target class.- Specified by:
readin classcom.google.gson.TypeAdapter<T>- Throws:
java.io.IOException
-
-