I am making a query call to freebase and I receive a JSON response. The response has the following structure:
{
"code": "/api/status/ok",
"result": [
{
"/common/topic/image": [{
"guid": "#9202a8c04000641f8000000004b67f6d"
}],
"/people/person/profession": [{
"name": "Critic"
}],
"id": "/en/michael_jackson_1942",
"name": "Michael Jackson",
"type": "/people/person"
},
{
"/common/topic/image": [{
"guid": "#9202a8c04000641f800000001b90fdea"
}],
"/people/person/profession": [{
"name": "Actor"
}],
"id": "/en/michael_jackson_1970",
"name": "Michael Jackson",
"type": "/people/person"
}
],
"status": "200 OK",
"transaction_id": "cache;cache03.p01.sjc1:8101;2012-01-16T18:28:36Z;0055"
}
I need to parse this response in a ArrayList of java objects using GSON. To do this I need to create the class of the object with get/set and make it available to parse. Or is there another simpler way to do things ? I have used simple JSON strings by now, but in this case I can't remake the structure of the class I need. Basically in the end I need something like ArrayList<Person>
where Person
has all the attributes from the json string.
Any help is appreciated. Thank you.
The final solution, according with the answer below
public class FreebaseResponse {
@SerializedName("code")
public String code;
@SerializedName("result")
public ArrayList<Person> result;
@SerializedName("status")
public String status;
@SerializedName("transaction_id")
public String transaction_id;
}
public class Person {
@SerializedName("/common/topic/image")
public ArrayList<Person.Guid> imageGuid;
@SerializedName("/people/person/profession")
public ArrayList<Person.Profession> profession;
@SerializedName("id")
public String id;
@SerializedName("name")
public String name;
@SerializedName("type")
public String type;
private class Guid
{
@SerializedName("guid")
public String guid;
}
private class Profession
{
@SerializedName("name")
public String name;
}
}