Markus Rathgeb created ARIES-1966:
-------------------------------------

             Summary: JAX-RS MediaType annotation is not correctly evaluated
                 Key: ARIES-1966
                 URL: https://issues.apache.org/jira/browse/ARIES-1966
             Project: Aries
          Issue Type: Bug
          Components: jax-rs-whiteboard
    Affects Versions: jax-rs-whiteboard-1.0.6, jax-rs-whiteboard-1.0.5
            Reporter: Markus Rathgeb


I realized that my _JaxrsExtension_ for _JaxrsMediaType_ _APPLICATION_JSON_ is 
not only used for endpoints that produces JSON (marked by annotation) but also 
for endpoints that produces plain text (marked by annotation)
 
For testing purposed I used a message body reader and writer implementation for 
the JSON media type that is using GSON.
 
The annotations and class declaration looks like:
 
{code:java}
@Component(scope = PROTOTYPE)
@JaxrsApplicationSelect("(osgi.jaxrs.name=*)")
@JaxrsExtension
@JaxrsMediaType(APPLICATION_JSON)
public class GsonMessageBodyReaderWriter<T> implements MessageBodyReader<T>, 
MessageBodyWriter<T> { ... }{code}
 
I see that this class is used for media type JSON and PLAIN_TEXT.
 
So I created another message body reader for media type plain text and a higher 
service ranking (just for testing).
 
{code:java}
@Component(scope = PROTOTYPE)
@ServiceRanking(100)
@JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=*)")
@JaxrsExtension
@JaxrsMediaType(MediaType.TEXT_PLAIN)
public class PlainTextMediaTypeExtension<T> implements MessageBodyReader<T>, 
MessageBodyWriter<T> { ... }{code}
 
If both components are available I would assume the PlainTextMediaTypeExtension 
is used for the media type plain text and the GsonMessageBodyReaderWriter is 
used for media type json (because of the JaxrsMediaType annotation.
 
But now PlainTextMediaTypeExtension is used for plain text AND JSON.
 
I would expect that the message body writer provided by 
{code:java}
@JaxrsExtension
@JaxrsMediaType(MediaType.TEXT_PLAIN){code}
is used for
{code:java}
@Produces(MediaType.TEXT_PLAIN){code}
and the message body writer provided by
{code:java}
@JaxrsExtension
@JaxrsMediaType(APPLICATION_JSON){code}
is used for
{code:java}
@Produces(MediaType.APPLICATION_JSON){code}
 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to