Bind multiple request parameters to one object in Spring 3

Posted by Max on Stack Overflow See other posts from Stack Overflow or by Max
Published on 2010-06-03T08:08:15Z Indexed on 2010/06/03 8:14 UTC
Read the original article Hit count: 360

Hi,

I can't figure out a way to bind several arguments and headers to one request parameter using annotations in Spring 3.

For example, let's say I'm getting this request:

Headers:
Content-type: text/plain;

POST Body:
Name: Max

Now I want it all to mysteriously bind to this object:

class NameInfo {
    String name;
}

Using some code like this:

String getName() {
    if ("text/plain".equals(headers.get("content-type"))) {
        return body.get("name");
    } else if ("xml".equals(headers.get("content-type")) {
        return parseXml(body).get("name");
    } else ...
}

So that in the end I would be able to use:

@RequestMapping(method = RequestMethod.POST)
void processName(@RequestAttribute NameInfo name) {
...
}

Is there a way to achieve something similar to what I need?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about beginner

Related posts about databinding