Configuring content-negotiation (JSON, XML, and so on)

In this recipe, we will see how to configure the way we want the system to decide which format to render depending upon the client expectations.

Getting ready

We are mostly going to review the XML configuration here. Then, we will test the API with different requests to ensure support is provided to the XML format.

How to do it...

  1. The RequestMappingHandlerAdapter configuration has been altered in dispatcher-context.xml. A contentNegotiationManager property has been added, as well as an xmlConverter bean:
    <bean class="org.sfw.web... method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="xmlConverter"/> <ref bean="jsonConverter"/> </list> </property> ...

Get Spring MVC Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.