2

I have a JSON string with a json array called "animals". the array contains "animal" objects. Each object has a "type" property (for example: "dog", "cat").

In my Java project, I have an Animal class, and Cat,Dog classes that inherit from it.

Is it possible, using GSON, to parse the "animals" JSON array according to their type?

Meaning, if I get to an object with "type":"cat", a Cat instance will be created and added to my Animal array. If "type":"dog", a Dog instance will be create.

dors
  • 5,802
  • 8
  • 45
  • 71

0 Answers0