@RequestBody map to object and get raw request string simultaneously

Viewed 845

I have use @RequestBody for mapping request to object at rest controller, but in the same time I need to get raw JSON from request without mapping. I don't map all JSON content to object. How to get simultaneously JSON raw and JSON mapped to object

 @RequestMapping(path = "/rest/web")
    public ResponseEntity<String> paymentHook( @RequestBody UserReq request, BindingResult bindingResult)

I can just get raw like this @RequestBody String payload, but then I must parse content "by hand"

1 Answers
**You can parse your JSON raw data to JSONObject and simply get all keys**

String mockResponse = "{\"customer\":{\"id\":34,\"email\":\"tt@gmail.com\"}\"}";
JSONObject jsonResponse = JSONObject.fromObject(mockResponse);
Related