I am using Retrofit API for communication. I want JSON Object to be stored directly in the Retrofit Result Bean. I tried the below process and it produced in null value. but while using postman the result is proper only.
The below is the output of the API
{
"status": 101,
"message": "Ok",
"type": 1,
"data": {
"value": "adakdj4lkj43"
}
}
public class ResponseBean {
private int status = 0;
private String message = "";
private int type = 0;
private JSONObject data = new JSONObject();
}
The concept you are trying to do is perfect. But the only thing here went wrong is using JSONObject in the Retrofit Bean. Retrofit is a library which convert the JSONObject to Bean Object. Better you try Object in stead of JSONObject. I think Retrofit does work on convert a part of JSONObject to Object. So try
public class ResponseBean {
private int status = 0;
private String message = "";
private int type = 0;
private Object data = new Object();
}
Instead of using this as DataType.
private JSONObject data = new JSONObject();