Generating XML
RESTful APIs sometimes return responses in different media types (JSON, XML, and so on). The mechanism responsible for choosing the correct media type is known as content negotiation in Spring.
By default, in Spring MVC, the ContentNegotiatingViewResolver
bean will be in charge of resolving the correct content according to the content negotiation policies defined in your application.
You can have a look at ContentNegotiationManagerFactoryBean
to see how these policies are applied within Spring MVC.
Content type can be resolved with the following strategies:
- According to the
Accept
header sent by the client - With a parameter such as
?format=json
- With a path extension such as
/myResource.json
or/myResource.xml
You can customize these strategies ...
Get Spring MVC: Designing Real-World Web Applications now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.