I have the following sample JSON:
{
"birds":[
{
"id":"SAMPLEID",
"isTest":true,
"externalId":{
"Main":[
"123ABC"
],
"Sub":[
"456"
]
},
"dinos":[
],
"rhinos":[
{
"id":"SUPER100ID",
"isTest":true,
"externalId":{
"famousId":[
"23|45"
]
},
"dinos":[
],
"pelicans":[
{
"id":"D4CLIK",
"isTest":true,
"bird":null,
"crazyArray":[
]
},
{
"id":"DID123",
"type":"B",
"name":"TONIE",
"isTest":true,
"bird":null,
"subspecies":[
]
}
]
}
]
}
],
"metaData":{
"count":1
}
}
I want to use GSON to deserialize this JSON String and get the value of "famousId" member only.
I have looked through other answers and it seems that I will absolutely need to create classes for this.
Would it be possible to deserialize this without mapping POJOs, using JsonParser, JsonElement, JsonArray, etc? I have tried several permutations of this but with no success.
I also have tried the following code but it is also not working as expected:
JsonObject o = new JsonParser().parse(jsonResponseString).getAsJsonObject();
Gson gson = new Gson();
enterprises ent = new enterprises();
ent = gson.fromJson(o, enterprises.class);
@Getter
@Setter
class birds {
@JsonProperty("rhinos")
List<Rhino> rhinos = new ArrayList<Rhino>();
}
@Getter
@Setter
class Rhino {
@JsonProperty("externalId")
ExternalId externalId;
}
@Getter
@Setter
@JsonPropertyOrder({
"famousId"
})
class ExternalId {
@JsonProperty("famousId")
List<String> famousId = new ArrayList<String>();
}
Unfortunately this does not work either, so I guess a two part question...is it possible to simply deserialize and get the String value for famousId that I want, and what is incorrect with my current class structure?