jersey
  1. jersey
  2. JERSEY-2489

@Custom annotation for MessageBodyWriter and MessageBodyReader is not honored

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Works as designed
    • Affects Version/s: 2.6
    • Fix Version/s: None
    • Component/s: core, media
    • Labels:
      None
    • Environment:

      Tomcat+Jersey

      Description

      Hi,
      I have a custom MessageBodyWriter and MessageBodyReader. I want to let Jersey to add my provider at the beginning of provider Chain. I registered my Provider like this
      X.register(myProvider.class, 1000).

      I noticed that at client side (clientConfig.register), the provider is always Custom provider. It is always non-custom provider whether I annotate the provider with @org.glassfish.jersey.internal.inject.Custom or not. The same behavior applies to ConfigurableMoxyJsonProvider.

      Also the bindingPriority (1000 here) is not honored since my provider is always behind ConfigurableMoxyJsonProvider. I want my provider before ConfigurableMoxyJsonProvider.

      How can I make jerset at server-side to know my provider is custom?

        Activity

        Hide
        jasonzhang2002gmailcom added a comment -

        It is always non-custom provider at server side(resourceConfig.register)

        Show
        jasonzhang2002gmailcom added a comment - It is always non-custom provider at server side(resourceConfig.register)
        Hide
        Michal Gajdos added a comment -

        Your provider is a custom one. Is your provider based on MOXy provider? Is it annotated with @Produces/@Consumes annotations or do you handle media types in isReadable/isWriteable methods?

        Show
        Michal Gajdos added a comment - Your provider is a custom one. Is your provider based on MOXy provider? Is it annotated with @Produces/@Consumes annotations or do you handle media types in isReadable/isWriteable methods?
        Hide
        jasonzhang2002gmailcom added a comment -

        Here is how my provider looks like

        
        
        @Provider
        @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML} )
        @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
        @Custom
        @Priority(1000)
        public class JaxbJsonProvider implements MessageBodyReader<Object>, MessageBodyWriter<Object>{
        ....
        }
        
        

        I add breakpoint in jerysey code so I can find out whether it is custom or not. At client side, it is. At server side, it is not.

        -jason

        Show
        jasonzhang2002gmailcom added a comment - Here is how my provider looks like @Provider @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML} ) @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @Custom @Priority(1000) public class JaxbJsonProvider implements MessageBodyReader< Object >, MessageBodyWriter< Object >{ .... } I add breakpoint in jerysey code so I can find out whether it is custom or not. At client side, it is. At server side, it is not. -jason
        Hide
        jasonzhang2002gmailcom added a comment -

        I worked around this by
        1. make JaxbJsonProvider a generic class.

        public class JaxbJsonProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<T>{
        ....
        }
        

        2. Make a subclass for every type JaxbJsonProvider can handle.

        public class Y extends JaxbJsonProvider<x> {
        //no code
        }
        

        3. register all subclasses.
        config.register(Y.class);

        Show
        jasonzhang2002gmailcom added a comment - I worked around this by 1. make JaxbJsonProvider a generic class. public class JaxbJsonProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<T>{ .... } 2. Make a subclass for every type JaxbJsonProvider can handle. public class Y extends JaxbJsonProvider<x> { //no code } 3. register all subclasses. config.register(Y.class);
        Hide
        Marek Potociar added a comment -

        You do not need to use @Custom annotation at all. Jersey will add one implicitly for you. Your problem seems to be caused by @Priority(1000). Try to set a lower priority or to remove this annotation completely.

        Show
        Marek Potociar added a comment - You do not need to use @Custom annotation at all. Jersey will add one implicitly for you. Your problem seems to be caused by @Priority(1000). Try to set a lower priority or to remove this annotation completely.

          People

          • Assignee:
            Unassigned
            Reporter:
            jasonzhang2002gmailcom
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Agile