I am trying to convert some JSON into a java object in android, however it does not seem to work.
Gson gson = new Gson();
Person person = gson.fromJson(s, Person.class);
Toast toast = Toast.makeText(getApplicationContext(), "Welcome back " + person.getDisplayName(), duration);
toast.show();
Where Person.class is
com.google.api.services.plus.model.Person
I am getting type conversion errors such as:
wrong object type: Ljava/lang/Double; Ljava/lang/Integer;
java.lang.IllegalArgumentException: invalid value for field
But I want to reuse this model object from the API library, so is there anyway to fix this?
EDIT:
To prove this problem in a more simple form, please refer to this example.
com.google.api.services.plus.model.Person;
Gson g = new Gson();
Person p1 = new Person();
p1.setDisplayName("Test");
p1.setCircledByCount(10);
String json = g.toJson(p1);
Person fromJson = g.fromJson(json, Person.class);
System.out.println(fromJson.getDisplayName());
Throws the same exception.
Exception in thread "main" java.lang.IllegalArgumentException: Can not set java.lang.Integer field com.google.api.services.plus.model.Person.circledByCount to java.lang.Double
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source)
Am I doing something wrong? Thanks