I know there have been a lot of questions on this topic already, but I'm stuck here and I'm sure it's something quite stupid.
I'm parsing a JSON Api that looks like this (renamed & simplified here):
{
"merchant": {
"name": "TestCo",
"id": 108
},
"category": [
{
"merchant_id": 108,
"category_name": "Baby Supplies",
"category_id": 57,
},
{
"merchant_id": 108,
"category_name": "Dining",
"category_id": 59,
}
]}
I have a wrapper class, defined as:
public class WrapperObject {
public MerchantObject merchant;
public List<CategoryObject> category;}
Both merchant & category are properly defined classes of their own. Then I try to deserialize like so:
collectionType = new TypeToken<List<WrapperObject>>() {}.getType();
List<WrapperObject> wrapperObject = new Gson().fromJson(response, collectionType);
This blows up, GSON reports back "This is not a JSON Array".
This worked perfectly right up until last week, when the API changed. The only difference in the JSON was that it used to look like this (note the extra wrapping array around the data):
[{
"merchant": {
"name": "TestCo",
"id": 108
},
"category": [
{
"merchant_id": 108,
"category_name": "Baby Supplies",
"category_id": 57,
},
{
"merchant_id": 108,
"category_name": "Dining",
"category_id": 59,
}
]}]
How do I adjust my code to parse the new JSON? NB, I have no control over the JSON. Thanks!