Skip to content

MediaType's include method does not check for generalization when using a format extension/suffix [SPR-9635] #14269

@spring-projects-issues

Description

@spring-projects-issues

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 and application/vnd.foo-response+xml for converting from and to XML
  • application/vnd.foo-request+json and application/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:

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions