Bind multiple request parameters to one object in Spring 3
- by Max
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.