Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jaxrs-dev] Thoughts on issue #546 (Allow to use @Produces and @Consumes at the Application class)

Hi folks,

I'd like to get your attention on an issue I originally created that I think would be easy to implement and reduce boilerplate: https://github.com/eclipse-ee4j/jaxrs-api/issues/546

3.5 @Consumes and @Produces "MAY be applied to a resource method, a resource class, or to an entity provider. [...] In the absence of either of these annotations, support for any media type (“*/*”) is assumed."

Most REST services only allow a specific set of  media types (tipically JSON and/or XML). People usually end up having to write the @Consumes("application/json") and  @Produces("application/json") on all resources. Annotation inheritance at class level (using a BaseResource class) is explicitly disabled: 3.6 "Note that inheritance ofclass or interface annotations is not supported."

Therefore I think it should be pretty easy and useful to support putting those annotations on the Application class to determine the default value.

PS: As a side note, if JAX-RS components were CDI beans, this could be easily acomplished by user code via a CDI extension, searching for the annotation on the Application class, and applying that same annotation at runtime to any resource bean not declaring anything more specific. Just one more point towards CDI integration :)


Regards,

Guillermo González de Agüero

Back to the top