-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Robert Gacki opened SPR-9635 and commented
Lets say I have an annotated handler method:
@RequestMapping
public @ResponseBody FooResponse doFoo(@RequestBody FooRequest) {
}
And I have HttpMessageConverters that can convert various formats like XML and JSON by looking at the format extension of the MediaType's subtype. In the example, this would be:
application/vnd.foo-request+xml
andapplication/vnd.foo-response+xml
for converting from and to XMLapplication/vnd.foo-request+json
andapplication/vnd.foo-response+json
for converting from and to XML
I do not want to pollute my handler methods with the format because the format handling is delegated to the HttpMessageConverters:
@RequestMapping(consumes = "application/vnd.foo-request", produces = "application/vnd.foo-response")
public @ResponseBody FooResponse doFoo(@RequestBody FooRequest) {
}
The MediaType classes' include method does not allow this scenario. It checks whether the subtype without the suffix is a wildcard and therefore matching: application/*+xml includes application/vnd.foo-response+xml
.
But it does not check the generalization: application/vnd.foo-response includes application/vnd.foo-response+xml
or application/soap includes application/vnd.foo-response+json
.
So my method, that does not want to know how about the RequestBody's / ResponseBody's serialized format, can not be found by the HandlerMapping (RequestMappingHandlerMapping).
Affects: 3.1.1
Issue Links:
- MappingJacksonHttpMessageConverter default media type should include *+json [SPR-7905] #12560 MappingJacksonHttpMessageConverter default media type should include *+json ("duplicates")