If I use 'web-send-json-response="true"' while calling any service, it returns json response using sendJsonResponse(Object responseObj) method of WebFacadeImpl.groovy. Where It adds 'errors' to json response if 'eci.getMessage().hasError()' true. But, Is there any reason why messages are not added in Json Response?
As I am willing to have messages in json response, I added few lines in sendJsonResponse() method. The code block where I added few lines to add messages to json response:
} else if (responseObj != null) {
responseObj.put("messages", eci.message.messages)
JsonBuilder jb = new JsonBuilder()
jb.call(responseObj)
jsonStr = jb.toString()
response.setStatus(HttpServletResponse.SC_OK)
} else {
jsonStr = ""
if (eci.message.messages) {
responseObj.put("messages", eci.message.messages)
JsonBuilder jb = new JsonBuilder()
jb.call(responseObj)
jsonStr = jb.toString()
}
response.setStatus(HttpServletResponse.SC_OK)
}
It works fine and I am getting messages in json response.