Recently, I got an issue with Gson deserialization. This is my object:
class Foo{
public List<Donation> donations;
class Donation{
// SerializedName here.
}
}
This is my json:
{
"donations": [] // sometimes, this array is empty.
}
// this is none empty one.
{
"donations": [
{
"doner_id": 4,
"name": "abc",
"donate": "103"
}
]
}
When parsing this JSON with the above object, I always got the error: Expected a com.google.gson.JsonObject but was com.google.gson.JsonArray
. If the donations
above is not empty, everything works well. How can I do to resolve it?