I have an endpoint /test
which expects Map
:
@POST("/hello")
@PermitAll
public JSONObject test(Map param) throws JsonParseException {
String elementName = param.get("name").toString();
String elem = param.get("elem").toString();
JSONObject json=new JSONObject();
try {
json.put("id",1);
} catch (JSONException e) {
e.printStackTrace();
}
return json;
}
And I'm sending asynchronous POST (postin JSON) using AsyncHttpClient
:
public static void asyncCallPost(JSONObject jsonData) throws Exception {
AsyncHttpClient client = new AsyncHttpClient();
try {
Response response = client.preparePost(url)
.addHeader("Content-Type", "application/json")
.addHeader("Content-Length", "" + jsonData.length())
.setBody(jsonData.toString()).execute().get();
if (response.getStatusCode() != 200) {
throw new Exception("Error ");
}
} finally {
client.close();
}
}
But I am getting java.lang.NullPointerException
.
Is it because I don't pass any Map to /hello
? If so how make POST
with jsonData
as Map
to the endpoint?