I have read the previously asked questions but none of them helped me.
My class is:
Class A{
String name;
JSONArray phone;
.....
}
I am using Rest client to send request and request is like:
{"name":"abc","phone":[{"no":"1234","type":"landline"},{"no":"4321","type","office"}]}
Now schema of this request is valid but when I send request my application throws an exception like:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY
I am mapping request to class as:
Gson gson=new Gson();
A para = null;
try{
para = gson.fromJson(json, A.class);
}catch(Exception e){
e.printStackTrace();
return false;
}
Could someone explain that why my array in the request is not getting mapped with the array in class A?