-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Closed
Copy link
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancementA general enhancement
Milestone
Description
Felix Barnsteiner opened SPR-9807 and commented
The following configuration won't work for accept headers containing e.g. application/vnd.foo.user+json (see also http://stackoverflow.com/questions/11880359/spring-mvc-3-1-1-contentnegotiatingviewresolver-how-to-use-wildcard-characters):
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1"/>
<property name="favorPathExtension" value="false"/>
<property name="defaultViews">
<list>
<!-- JSON View -->
<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
<property name="contentType" value="application/*+json"/>
</bean>
</list>
</property>
</bean>
The reason is a wrong comparison in ContentNegotiatingViewResolver#getBestView:
Current:
for (MediaType mediaType : requestedMediaTypes) {
for (View candidateView : candidateViews) {
if (StringUtils.hasText(candidateView.getContentType())) {
MediaType candidateContentType = MediaType.parseMediaType(candidateView.getContentType());
if (mediaType.includes(candidateContentType)) {
if (logger.isDebugEnabled()) {
logger.debug("Returning [" + candidateView + "] based on requested media type '"
+ mediaType + "'");
}
return candidateView;
}
}
}
}
The problem is application/vnd.foo.user+json does not include application/*+json, the opposite is true.
Expected:
if (candidateContentType.includes(mediaType)) {
Affects: 3.1.2
Reference URL: http://stackoverflow.com/questions/11880359/spring-mvc-3-1-1-contentnegotiatingviewresolver-how-to-use-wildcard-characters
Issue Links:
- MappingJacksonHttpMessageConverter default media type should include *+json [SPR-7905] #12560 MappingJacksonHttpMessageConverter default media type should include *+json
Referenced from: commits c7e7e80
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancementA general enhancement