I have a JSON response coming back from my server in the format:
[
{
"id": "one",
"values": {
"name": "John",
}
},
{
"id": "two",
"values": {
"name": "Bob",
}
}
]
Here is the class I've set up:
public class TestClass implements Serializable {
@SerializedName("id")
private String id;
@SerializedName("values")
private List<String> values;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
}
Here is my code to parse the JSON into a list of objects:
String response = serverResponseHere;
Gson gson = new Gson();
String json = gson.toJson(response);
Type collectionType = new TypeToken<List<TestClass>>(){}.getType();
List<TestClass> values = gson.fromJson(json, collectionType);
However, I get the following error:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING
What's going on here?