I retrieve a JSON result from an API :
[{
"oid": "axd7wtlk6xd2fbwlc5wk",
"id": "aazzzza",
"name": "aazzaa",
"logo": {
"type": 0,
"data": "iVB.............5CYII="
},
"timestamp": 1438608571013,
"email": "[email protected]",
"modified": "test",
"url": "http://www.azzaa.net"
},
{
"oid": "quj3dzygfwygl5uxsbxk",
"name": "KZZZ",
"modified": "test",
"timestamp": 1438854099511,
"id": "kess"
},...]
but when I try to map to a customer object I get the error Expected a string but was BEGIN_OBJECT :
response = webService.RequestGet(url, header);
result = null;
try {
result = new JSONArray(response);
Utils.LogWarning(response);
} catch (JSONException e) {
Utils.LogError("Could not load json response", e);
}
Type customerType = new TypeToken<Collection<Customer>>() {
}.getType();
ArrayList<Customer> alCustomers = null;
alCustomers = new Gson().fromJson(result.toString(), customerType);
Here is my Customer class :
public class Customer implements Serializable {
private String id = "";
private String name = "";
private String email = "";
private String url = "";
private String address = "";
private String stamp = "";
//private transient String logo = "";
private long timestamp = 0L;
private String modified = "";
...
}
I have been through a lot of answers regarding this problem that I have also for other types of objects, but I can't find a working solution.
Customerclass, islogofield a String?customerclassCustomerclass properties type with the type you have in JSON.transientkeyword as I will store the path and not the image