I'm trying to parse a response JSON string from the server into my POJO objects using Gson. Below is my JSON:
{
"user":{
"id":"859adb60-4a47-4e1b-8f40-10480bfc33ec",
"createdAt":"2017-05-11T07:52:43.661Z",
"updatedAt":"2017-05-11T07:52:43.786Z",
"version":"AAAAAAA0GXQ=",
"deleted":false,
"userName":null,
"bucketId":"7c2b3ce4-ac5d-4e6a-a6c1-d6316c01fcfb",
"userEmailId":"test1@tilicho.in",
"signupType":"Custom",
"userAvatar":null,
"userPin":"$2a$10$9TCIqHrE6jDZMr0lhHRddeC7kU.Ob6s8o8zG3ahsmaAMBNi5Gkvwy",
"verified":true,
"verifyHash":"IpkzqvjHGb6nbdxxkvmgLiPJRSRhUJ6wMOO3V7Gz5ispOlpLPtdGMTkldzOwHp3Q",
"thirdPartyToken":null,
"loginAgent":null,
"isDataSetUp":false
},
"colloboratedChildren":[
],
"invitations":[
{
"id":"4892167b-bc6a-47e5-bb30-1785b5643edc",
"createdAt":"2017-05-11T07:52:06.019Z",
"updatedAt":"2017-05-11T07:52:06.019Z",
"version":"AAAAAAA0GWY=",
"deleted":false,
"inviterId":"9d00f972-e66d-400b-b332-f0b873a8b1fd",
"inviterEmail":"nemani@tilicho.in",
"inviteeId":null,
"inviteeEmail":"test1@tilicho.in",
"inviteData":"{\"821e63e7-457e-401f-b071-abacd51bcbad\":[\"B690E26C-BA39-45E3-BB34-CF6EABB666F7\"]}"
}
],
"authToken":"bQYng6AAeCp9HlR1rCZeOCbFUm1LaRfVzcqTWpgXiLul3tFj7Y4hKr997V6hvl6d"
}
Here are my POJO classes.
@Getter
@Setter
public class LoginResponse {
User user;
ArrayList<ColloboratedChildren> colloboratedChildren;
ArrayList<InvitationResponse> invitations;
String authToken;
}
@Getter
@Setter
public class User extends BucketAzureModel {
private String signupType;
private String userAvatar;
private String userEmailId;
private String userName;
private String userPin;
}
@Getter
@Setter
ColloboratedChildren {}
public class InvitationResponse {
String id;
String createdAt;
String updatedAt;
String version;
boolean deleted;
String inviterId;
String inviterEmail;
String inviteeId;
String inviteeEmail;
Map<String, ArrayList<String>> inviteData;
}
The code that is converting the JSON to POJOs:
JsonEntityParser.parseResults(jsonElement, gsonBuilder.create(), concreteClass);
Here is the error I am facing:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at path $.invitations[0].inviteData
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at com.google.gson.Gson.fromJson(Gson.java:925)
at com.microsoft.windowsazure.mobileservices.table.serialization.JsonEntityParser.parseResults(JsonEntityParser.java:64)
From the error I understand that Gson is expecting a {
where there is a "
, but I don't exactly understand how to create a Map<String, ArrayList<String>>
at inviteData
from the given response. I don't really get how to define my POJO in order to parse the incoming JSON. Please note that I can't change the format of the JSON, I have to adhere to this format only. Any help would be really appreciated.