Java Google Json (Gson) Serializing Generics

Serializing list

As we saw in the previous tutorial serializing and deserializing classes with generic types is non trivial since generic type information is lost while serializing. Gson provides a class called com.google.gson.reflect.TypeToken to store generic types. The example below shows how to use the TypeToken class to serialize and deserialize Classes with generic types.

Animal class

Dog Class

One thought on “Java Google Json (Gson) Serializing Generics

  • February 19, 2018 at 12:10 pm
    Permalink

    In this and other tutorials, the code for the diamond operator is shown as HTML metas, I mean instead of “”, “<” and “>” are printed.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *