Results 1 to 2 of 2

Thread: RESTful Service, accept application/x-www-form-urlencoded and application/json

  1. #1
    Join Date
    Feb 2012
    Posts
    3

    Default 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.

  2. #2
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    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
  •