Skip to content

Instantly share code, notes, and snippets.

@bjpeterdelacruz
Last active January 11, 2018 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjpeterdelacruz/ab119548c0c67d8241c6 to your computer and use it in GitHub Desktop.
Save bjpeterdelacruz/ab119548c0c67d8241c6 to your computer and use it in GitHub Desktop.
Multiple Content Types
@RequestMapping(value = "pdf", headers = { "Accept=*/*",
"content-type=application/json,text/plain" }, method = RequestMethod.POST, produces = "application/pdf")
public ResponseEntity<byte[]> getPdf(@RequestBody Object object) {
Form form;
if (object instanceof Map) {
form = new ObjectMapper().convertValue(object, Form.class);
}
else {
try {
form = formService.getForm(Long.parseLong(object.toString()));
}
catch (Exception e) {
return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY);
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment