Reputation: 881
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"
Upvotes: 1
Views: 1878
Reputation: 106
**You can parse your JSON raw data to JSONObject and simply get all keys**
String mockResponse = "{\"customer\":{\"id\":34,\"email\":\"[email protected]\"}\"}";
JSONObject jsonResponse = JSONObject.fromObject(mockResponse);
Upvotes: 0