Gson Json Parsing in Java Gson Json Parsing in Java json json

Gson Json Parsing in Java


Unfortunately Gson isn't as straight forward in certain aspects as, for example, Jackson - where you can simply use the annotation @JsonIgnore.

On the other hand, Gson seems to have more flexibility (although a little too technical sometimes.)

In the case of Gson you have two main options to achieve what you want:

  1. Mark the field you want to ignore as transient: private transient String id (in this case you have to make sure that this won't cause any side effects in your application.)
  2. You can use the very flexible capabilities of Gson, especially the annotation @Expose. for example:

    @Expose(Serialize = false)private String id;

You can find more examples and details here and here.

Please, let us know if it helps.