How can I take an xml that looks like:
<request>
<User>
<name>name value</name>
<age>13</age>
</User>
</request>
And then I can deserialize this into a User object that has matching properties.
public class User {
private String name;
private Integer age;
// getter and setters
}
Is there anything simple I can do or do I have to parse the xml manually for this?
I’m using spring mvc, and this is in a method where the xml will be posted.
Your controller method should take an argument of type
User, which is annotated with@RequestBody. Then you need to configure aMarshallingHttpMessageConverterwith an appropriate marshaller/unmarshaller. An example, straight from the reference guide:Take a look at “Supported method argument types” and “Mapping the request body with the @RequestBody annotation” in the reference guide for more details.