Good day!
I'm trying to parse a json string using the gson library. I have this class:
class Foo { int Id; String Name; }
and, for example, this line:
{response: [123, { id: 1, name: 'qwerty'}, { id: 2, name: 'asdfgh'}, ]}
I'm trying to deserialize it like this:
Gson gson = new Gson(); Foo[] res = gson.fromJson(jsonStr, Foo[].class);
But when I try to run it, I get an error. The problem here is that the string does not contain an array of json objects, but an object with a response field, which is an array, but I would like to deserialize only the array itself. The second problem is that in the array, besides elements that can be deserialized as objects of the Foo class, there is also a prime number 123, which cannot be deserialized as Foo.
My question is: can I somehow "tell" the deserializer that I want to deserialize only the contents of the response object and that I want to skip the value 123 in the array and not deserialize it? Or do I need to parse a string and somehow select the necessary data in it? I would not like to do it manually.