I am expecting a JSONArray
with a list of JSONObjects in the response that was originally passed in the request body. However, I'm getting a success response with an empty JSONArray
. I'm certain that the API is working fine since I tested it on Postman.
JsonArrayRequest arrayRequest = new JsonArrayRequest(DownloadManager.Request.Method.POST, URL, jsonArray,
ResSuccessListenerForJsonArray(requestType),
ResErrorListenerForJsonArray(requestType)
) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers != null ? headers : super.getHeaders();
}
};
I'm spawning an AsyncTask
from the job service to make the request.
Here's a snippet of the response:
[
{
"id": "902b7fc3-5059-4265-85eb-d00db3594af5",
"user": "test@gmail.com",
"package":"com.whatsapp",
.
.
.
},
{
"id": "902b7fc3-5059-4265-85eb-d00db3594af5",
"user": "test@gmail.com",
"package":"com.whatsapp",
.
.
.
},
.
.
.
]
This is my response handler:
private static Response.Listener<JSONArray> ResSuccessListenerForJsonArray(final String requestType) {
return new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.e("Success", "Notification data logged successfully");
if (response != null && response.length() > 0) {
try {
handleSuccess(requestType, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
}