GSON API At Glance


There are 4 key packages in gson api those are

Package Name Description
com.google.gson This package provides the Gson class to convert Json to Java and vice-versa.
com.google.gson.annotations This package provides annotations that can be used with Gson.
com.google.gson.reflect This package provides utility classes for finding type information for generic types.
com.google.gson.stream
 

>_com.google.gson

  • com.google.gson is the core and key package of gson using the classes of this package we can create the instance for GSON.

    'com.google.gson' Package contains more than 10 classes out of those key classes some of those are

    Class Name Description
    Gson This is the main class for using Gson.
    GsonBuilder Use this builder to construct a Gson instance when we need to set configuration options other than the default.
    TypeAdapter<T> Converts Java objects to and from JSON.
    JsonParser A parser to parse Json into a parse tree of JsonElements

>_com.google.gson.annotations

  • com.google.gson.annotations It contains the annotations that can be used with Gson.

    'com.google.gson.annotations' Package contains Only 5 Anotations (ver 2.7) those are

    Annotation Name Description
    Expose An annotation that indicates this member should be exposed for JSON serialization or deserialization.
    JsonAdapter An annotation that indicates the Gson TypeAdapter to use with a class or field.
    SerializedName An annotation that indicates this member should be serialized to JSON with the provided name value as its field name.
    Since An annotation that indicates the version number since a member or a type has been present.
    Until An annotation that indicates the version number until a member or a type should be present.

>_com.google.gson.reflect

  • com.google.gson.reflect package provides utility classes for finding type information for generic types

    'com.google.gson.reflect' Package contains Only one class (ver 2.7) that is

    Class Name Description
    TypeToken<T> Represents a generic type T.
we can view the examples for the above ones in next chapters.