JSONObject jsonResponse = new JSONObject();
jsonResponse.put("result", "");
//get response to send to client
return jsonResponse.toString().getBytes("UTF-8");
} catch (Exception e) {
throw new ServiceRuntimeException("Unable to create JSON response", e);
}
} else {
// regular operation returning some value
try {
result = responseMessage.getBody();
JSONObject jsonResponse = new JSONObject();
//JSONObject put will remove the entry if it's value is null
//and per javadoc, we should pass JSONObject.NULL
if(result == null) {
jsonResponse.put("result", JSONObject.NULL);
} else {
jsonResponse.put("result", result);
}
jsonResponse.putOpt("id", id);
//get response to send to client
return jsonResponse.toString().getBytes("UTF-8");
} catch (Exception e) {
throw new ServiceRuntimeException("Unable to create JSON response", e);
}
}
}
} else {
//exception thrown while executing the invocation