RESTEasy
  1. RESTEasy
  2. RESTEASY-551

Decorator for Jaxb unmarshaller doesn't work

    Details

    • Similar Issues:
      Show 10 results 

      Description

      I've created @Validate decorator annotation and define ValidatorProcessor to enable schema validation while unmarshalling. But decorator doesn't work - it's not registered.I think the problem is with empty annotations, passed to readFrom method of AbstractJAXBProvider. Marshalling decorators work fine.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            Alexander Primak added a comment -

            This is code fragment from org.jboss.resteasy.core.interception.DecoratorMatcher's decorate(Class<T> targetClass, T target, Class type, Annotation[] annotations, MediaType mediaType) method:

            // override any class level ones
            if (annotations != null)
            {
            for (Annotation annotation : annotations)
            {
            Decorator decorator = annotation.annotationType().getAnnotation(Decorator.class);
            if (decorator != null && targetClass.isAssignableFrom(decorator.target()))

            { meta.put(annotation.annotationType(), annotation); }

            }
            }

            Show
            Alexander Primak added a comment - This is code fragment from org.jboss.resteasy.core.interception.DecoratorMatcher's decorate(Class<T> targetClass, T target, Class type, Annotation[] annotations, MediaType mediaType) method: // override any class level ones if (annotations != null) { for (Annotation annotation : annotations) { Decorator decorator = annotation.annotationType().getAnnotation(Decorator.class); if (decorator != null && targetClass.isAssignableFrom(decorator.target())) { meta.put(annotation.annotationType(), annotation); } } }
            Hide
            Alexander Primak added a comment -

            And this is Spring MVC method annotated with JAX-RS annotations:

            @POST
            @Path(CalcController.CALCULATE_PATH)
            @Produces(MediaType.TEXT_PLAIN)
            @Consumes(MediaType.APPLICATION_XML)
            @Validate(schemaName = "some schema name")
            public Response calculate(InitialRequest initialRequest)

            { String requestId = requestScheduler.scheduleRequest(transformer.transform(initialRequest)); URI newURI = UriBuilder.fromUri(CHECK_STATUS_PATH).path(requestId).build(); return Response.status(Response.Status.ACCEPTED).entity(newURI.toString()).build(); }
            Show
            Alexander Primak added a comment - And this is Spring MVC method annotated with JAX-RS annotations: @POST @Path(CalcController.CALCULATE_PATH) @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_XML) @Validate(schemaName = "some schema name") public Response calculate(InitialRequest initialRequest) { String requestId = requestScheduler.scheduleRequest(transformer.transform(initialRequest)); URI newURI = UriBuilder.fromUri(CHECK_STATUS_PATH).path(requestId).build(); return Response.status(Response.Status.ACCEPTED).entity(newURI.toString()).build(); }
            Hide
            Alexander Primak added a comment -

            And this is DecoratorProcessor implementation:

            @DecorateTypes(

            {"text/*+xml", "application/*+xml", MediaType.APPLICATION_XML, MediaType.TEXT_XML}

            )
            public class ValidationProcessor implements DecoratorProcessor<Unmarshaller, Validate> {

            private static final Log logger = LogFactory.getLog(ValidationProcessor.class);

            public Unmarshaller decorate(Unmarshaller target, Validate annotation,
            Class type, Annotation[] annotations, MediaType mediaType) {
            ......................

            Show
            Alexander Primak added a comment - And this is DecoratorProcessor implementation: @DecorateTypes( {"text/*+xml", "application/*+xml", MediaType.APPLICATION_XML, MediaType.TEXT_XML} ) public class ValidationProcessor implements DecoratorProcessor<Unmarshaller, Validate> { private static final Log logger = LogFactory.getLog(ValidationProcessor.class); public Unmarshaller decorate(Unmarshaller target, Validate annotation, Class type, Annotation[] annotations, MediaType mediaType) { ......................
            Hide
            Bill Burke added a comment -

            Put the annotation as a parameter annotation on the thing you are unmarshalling/validating.

            Show
            Bill Burke added a comment - Put the annotation as a parameter annotation on the thing you are unmarshalling/validating.
            Hide
            Alexander Primak added a comment -

            Thanks, Bill! It works fine, when annotation is used as parameter annotation.

            Show
            Alexander Primak added a comment - Thanks, Bill! It works fine, when annotation is used as parameter annotation.
            Hide
            Sanketi Mehta added a comment -

            Can you please specify or provide example where the parameter annotation was added in this case? I am unclear on Bill's comment. Thanks.

            Show
            Sanketi Mehta added a comment - Can you please specify or provide example where the parameter annotation was added in this case? I am unclear on Bill's comment. Thanks.
            Hide
            Alexander Primak added a comment -

            You should put your annotation before parameter you want to decorate.
            In this case the code above will look like this:

            @POST
            @Path(CalcController.CALCULATE_PATH)
            @Produces(MediaType.TEXT_PLAIN)
            @Consumes(MediaType.APPLICATION_XML)
            public Response calculate(@Validate(schemaName = "some schema name") InitialRequest initialRequest)

            { ///// some logic }
            Show
            Alexander Primak added a comment - You should put your annotation before parameter you want to decorate. In this case the code above will look like this: @POST @Path(CalcController.CALCULATE_PATH) @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.APPLICATION_XML) public Response calculate(@Validate(schemaName = "some schema name") InitialRequest initialRequest) { ///// some logic }

              People

              • Assignee:
                Bill Burke
                Reporter:
                Alexander Primak
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development