-
Feb 20th, 2012, 02:32 PM
#1
RESTful Service, accept application/x-www-form-urlencoded and application/json
I'm fairly new to Spring and I am trying to work out a flexible way to do restful services.
To accept true JSON input, I use the @RequestBody tag. But doing so causes form urlencoded data to no longer be accepted.
Is there a standard way to allow both? Or do I need to create multiple create & update methods, using mappings like this:
@RequestMapping(value={"/test"}, headers = "content-type=application/x-www-form-urlencoded")
@RequestMapping(value={"/test"}, headers = "content-type=application/json")
I'm wondering if there is perhaps something I am overlooking here. I understand content negotiation on the reply side (using ContentNegotiatingViewResolver). But is there something similar for the input side?
If not, what is the standard way to accept RESTful input? As a JSON object or as form urlencoded?
Thanks for any help.
-
Feb 24th, 2012, 05:34 PM
#2
It's not clear what the exact problem you're running into is but in Spring 3.1 you can use the consumes/produces conditions. Check the reference documentation.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules