I have a group of classes of models that have a type field List<X>, where X- one of many things (for example String, Integerbut also some of my own type). I use GSON to analyze the JSON representations of these models. My problem is that the server I am facing (which is out of my control) somehow deleted singleton arrays and replaced them with the contained object. For example, instead of returning:
{
"foo": [ "bar"],
"bleh": [ { "some": "object" } ]
}
It returns:
{
"foo": "bar",
"bleh": { "some": "object" }
}
Now suppose the Java model class looks something like this:
public class Model {
private List<String> foo;
private List<SomeObject> bleh;
}
This currently causes the GSON to throw an exception because it finds BEGIN_STRINGor BEGIN_OBJECTwhere it expects BEGIN_ARRAY.
TypeAdapter<List<String>>. , List , TypeAdapter . TypeAdapter<List<?>>, - .
, GSON , /? , , "", [ ] , , ?