Consider the following JSON
{
"category": [
{
"code": "JCAT02",
"value": " administrative"
},
{
"code": "CAT19",
"value": " government"
}
],
"studies": {
"code": "C",
"value": "Secundary degree"
}
}
This is a piece of a result I get from calling a rest api. When I call that same api but for a different item, I get this answer:
{
"category":
{
"code": "JCAT02",
"value": " administrative"
},
"studies": [
{
"code": "C",
"value": "Secundary degree"
},
{
"code": "E",
"value": "Master"
}
]
}
As you can see, the api is not very consequent in its answers and sometimes returns an object instead of an array. I wonder how i can deal with this in my Java object? I am getting "Expected BEGIN_ARRAY but was BEGIN_OBJECT at line" . I a naive spur of the moment, I tried putting a list (with annotation @SerializedName ) and the object with the correct name in my class definition, but to no avail as you cant have multiple fields with the same name.
Is there another obvious way of dealing with this? I did a fast search google, but couldn't find what I was looking for.