Uploaded image for project: 'Aries'
  1. Aries
  2. ARIES-1966

JAX-RS MediaType annotation is not correctly evaluated

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Invalid
    • Affects Version/s: jax-rs-whiteboard-1.0.5, jax-rs-whiteboard-1.0.6
    • Fix Version/s: None
    • Component/s: jax-rs-whiteboard
    • Labels:
      None

      Description

      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:
       

      @Component(scope = PROTOTYPE)
      @JaxrsApplicationSelect("(osgi.jaxrs.name=*)")
      @JaxrsExtension
      @JaxrsMediaType(APPLICATION_JSON)
      public class GsonMessageBodyReaderWriter<T> implements MessageBodyReader<T>, MessageBodyWriter<T> { ... }

       
      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).
       

      @Component(scope = PROTOTYPE)
      @ServiceRanking(100)
      @JaxrsApplicationSelect("(" + JaxrsWhiteboardConstants.JAX_RS_NAME + "=*)")
      @JaxrsExtension
      @JaxrsMediaType(MediaType.TEXT_PLAIN)
      public class PlainTextMediaTypeExtension<T> implements MessageBodyReader<T>, MessageBodyWriter<T> { ... }

       
      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

      @JaxrsExtension
      @JaxrsMediaType(MediaType.TEXT_PLAIN)

      is used for

      @Produces(MediaType.TEXT_PLAIN)

      and the message body writer provided by

      @JaxrsExtension
      @JaxrsMediaType(APPLICATION_JSON)

      is used for

      @Produces(MediaType.APPLICATION_JSON)

       

        Attachments

          Activity

            People

            • Assignee:
              csierra Carlos Sierra Andrés
              Reporter:
              maggu2810 Markus Rathgeb
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: