JAX-RS should support multiple exception mappers distinguished by @Produces
- Dominant language
- Java
- Stars
- 400
- Forks
- 143
- PR merge metrics
- No merged PRs in 30d
Description
It would be good to be able to have multiple sets of classes which work together to 'render' a set of
resources into a particular MIME type. As an example, imagine a sample system which is a simple music
information database (artists, CDs, and tracks). We want to be able to render these resources as HTML,
XML, or JSON (and in a manner that could be extended to other types in the future).
Keeping the renderings separate/orthogonal from each other requires that we have multiple
ExceptionMappers for the same exception which produce different media types. We tried doing
something like this:
=================
package net.gilstraps.music.html;
@Provider
@Produces( "text/html" )
public class NoSuchArtistMapper implements ExceptionMapper {
// ...
}
=================
package net.gilstraps.music.xml;
@Provider
@Produces( "application/music-xml" )
public class NoSuchArtistMapper implements ExceptionMapper {
// ...
}
=================
package net.gilstraps.music.json;
@Provider
@Produces( "application/json" )
public class NoSuchArtistMapper implements ExceptionMapper {
// ...
}
=================
But this does not work because media type is not considered when searching for an ExceptionMapper.
Please add this enhancement to the next version of the spec, so that truly separate code bases can co-
exist even when handling generated exception.
Thanks,
Brian Gilstrap
#### Environment
Operating System: All
Platform: Macintosh
#### Affected Versions
[2.0]
Contributor guide
Assessment
This issue has not been assessed yet.