Closed
Description
David Melia opened SPR-7905 and commented
Hi,
Currently in my REST service which supports both XML and JSON I am using the accept header so the same URL can provide different end points which will provide versioning. So my accept header is of the format
Accept=application/appname-v1+xml or Accept=application/appname-v1+json
which can route through the the v1 (version1) version of my REST method. The above is fine for XML as AbstractXmlHttpMessageConverter (subclass of Jaxb2RootElementHttpMessageConverter) registers the media type
new MediaType("application", "*+xml")
``` so this wildcard satisfies my accept header no problem.
However, for JSON, MappingJacksonHttpMessageConverter only registers ```
new MediaType("application", "json", DEFAULT_CHARSET)
``` which means I cannot use <mvc:annotation-driven/> out of the box :-(
Any chance we could have MappingJacksonHttpMessageConverter also registering ```
new MediaType("application", "*+json", DEFAULT_CHARSET)
This would result in a lot less configuration as I have to do the following in place of mvc:annotation-driven/
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters" ref="messageConverters" />
</bean>
<!-- Message converters -->
<util:list id="messageConverters">
<bean class="org.springframework.http.converter.StringHttpMessageConverter" />
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<bean class="org.springframework.http.MediaType">
<constructor-arg value="application" />
<constructor-arg value="json" />
</bean>
<bean class="org.springframework.http.MediaType">
<constructor-arg value="application" />
<constructor-arg value="*+json" />
</bean>
</list>
</property>
</bean>
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter" />
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
</util:list>
Thanks
Affects: 3.0.5
Issue Links:
- MediaType's include method does not check for generalization when using a format extension/suffix [SPR-9635] #14269 MediaType's include method does not check for generalization when using a format extension/suffix ("is duplicated by")
- ContentNegotiatingViewResolver does not support wildcards in contentType [SPR-9807] #14440 ContentNegotiatingViewResolver does not support wildcards in contentType
Referenced from: commits 8270d82, e16c403, 4f114a6
4 votes, 8 watchers