In the first case when it returns success true
, everything works, the problem when it gets success boolean is false
, then the error:
How Retrofit Response Array or Object either.
Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 26 path $ .data
Can it be done with one reponse class?
Json response:
{
"success": true,
"data": {
"message": "User created",
}
}
Json response:
{
"success": false,
"data": [
{
"code": "existing_user_login",
"message": "User Exist !"
}
]
}
Code:
public class Response {
public Boolean success;
public Data data;
public Boolean isSuccess() { return success; }
public Data getData() {
return data;
}
public class Data {
public String code;
public String message;
public String getMessage() { return message; }
public String getCode() { return code; }
}
}