Class DynamicModelTypeAdapterFactory

  • All Implemented Interfaces:
    com.google.gson.TypeAdapterFactory

    public class DynamicModelTypeAdapterFactory
    extends java.lang.Object
    implements com.google.gson.TypeAdapterFactory
    This class is registered with Gson to perform serialization and deserialization for dynamic model classes. Dynamic model classes are generated for JSON schemas that have the additionalProperties property set.

    These generated classes will extend DynamicModel<T>, where T represents the type of values that can be stored as additional (arbitrary) properties.
    Note that T could be:

    • Object
    • String
    • Long
    • etc.
    OR it could be a user-defined type (i.e. MyModel).

    Each generated dynamic model class will have zero or more explicitly-defined fields which model the schema properties found in the corresponding JSON schema, plus a map (inherited from DynamicModel) containing additional arbitrary properties.

    Limitations:
    Note that this type adapter is not a "full-function" type adapter like the internal Gson-provided ones. Specifically, this type adapter does not support all of the inclusion and exclusion options related to the serialization and deserialization of fields. Instead, each field defined on the class must be annotated with Gson's SerializedName annotation for it to be included in the serialization process.

    This class includes code that was adapted from the internal ReflectiveTypeAdapterFactory and MapTypeAdapterFactory classes from Gson.

    This class will explicitly serialize null values found within dynamic (additional) properties, regardless of the global "serialize nulls" setting in Gson.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  DynamicModelTypeAdapterFactory.Adapter<T>
      An adapter for serializing/deserializing instances of type T, where T represents a generated dynamic model class which is a subclass of DynamicModel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> com.google.gson.TypeAdapter<T> create​(com.google.gson.Gson gson, com.google.gson.reflect.TypeToken<T> type)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DynamicModelTypeAdapterFactory

        public DynamicModelTypeAdapterFactory()
    • Method Detail

      • create

        public <T> com.google.gson.TypeAdapter<T> create​(com.google.gson.Gson gson,
                                                         com.google.gson.reflect.TypeToken<T> type)
        Specified by:
        create in interface com.google.gson.TypeAdapterFactory