I have the requirement to return the result from the database either as a string in xml-structure or as json-structure. I\'ve got a solution, but I don\'t know, if this one
Here I wrote method which take XML as request parameter from your request mapping URL
Here I am posting XML to my URL "baseurl/user/createuser/"
public class UserController {
@RequestMapping(value = "createuser/" ,
method=RequestMethod.POST, consumes= "application/xml")
@ResponseBody
ResponseEntity createUser(@RequestBody String requestBody ) {
String r = "10 "; // Put whatever response u want to return to requester
return new ResponseEntity(
"Handled application/xml request. Request body was: "
+ r,
new HttpHeaders(),
HttpStatus.OK);
}
}
I tested it using chrome poster where you can send any xml in content body like:
" 3 saurabh shri pass test@test.com "
This XML will capture by my createUser method and stored in String requestBody which i can use further