Hello,
My app fails to parse a JSON string because it expects double quotes around the fields, I think.
Context:
The receives JSON responses from a server. A response always has three fields and the third can be anything (including arrays), depending on the type of request. For example,
{
"status":"OK",
"reason":"",
"data":null
}
or
{
"status":"OK",
"reason":"",
"data":{
"id":34,
"name":"name19",
"email":"email19",
"registerType":null,
"password":null
}
}
Naturally, I created a superclass that declares the three fields common to every response. Then, each subclass handles the field 'data' as appropriate (it simply uses a shared Gson object to parse that field into a POJO).
public class Response
{
//...
@Key private String status;
@Key private String reason;
@Key private Object data;
//...
}
Problem:
Now, the response is correctly parsed into a subclass of 'Response', meaning the field 'data' is processed and stored in 'Response.data'. However, when I attempt to deserialize its content, the parser fails and complains about a malformed JSON. When printed, 'Response.data' contains no quotes, as did the original JSON.
I'm not all too familiar with GSON and JSON in general, so I would greatly appreciate any piece of advice or solution the problem I'm facing.
Thank you,
Alexandre Vieira