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 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

Java Google Json (Gson) Serializing Generics

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

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

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top