I trying to populate a response object that looks like this using Gson:
public class RegisterUserResponse extends BaseResponse {
@SerializedName("tokens")
private Tokens tokens;
public RegisterUserResponse() { }
public Tokens getTokens() {
return tokens;
}
}
My Gson builder looks like this:
RegisterUserResponse response = getGson().fromJson(jsonResponse, RegisterUserResponse.class);
When I receive a JSON that contains the object everything's fine. The problem begins when "tokens" return empty, like in this JSON:
{"tokens":""}
and I get this exception:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line # column #
Which I do understand, but don't know how to avoid.