]
Michal Petrov commented on WFLY-10319:
--------------------------------------
[~jestevezsanchez], I don't think this is a bug. By design nested classes do not
inherit the annotations of their outer class and annotations are not inheritable by
default. That is core Java not something in the JAX-RS subsystem or RESTEasy. In order to
make something like this work you need to:
* make DemoSubResource extend DemoResource
* add \@Inherited to the name binding
NameBinding annotations on resources are ignored in subresources
----------------------------------------------------------------
Key: WFLY-10319
URL:
https://issues.jboss.org/browse/WFLY-10319
Project: WildFly
Issue Type: Bug
Affects Versions: 12.0.0.Final
Reporter: Javier Estevez Sanchez
Assignee: Jason Greene
The following JAX-RS resource exposes two resources via a GET operation: /demo and
/demo/subresource. The first one via a sub-resource method, the latter via a sub-resource
locator. Additionally, a response filter is binded to the JAX-RS resource class to modify
the response. From the JAX-RS 2.0 spec, ยง6.5.2 Name Binding:
{quote}
Binding annotations that decorate resource classes apply to all resource methods defined
in them.
{quote}
However, the binding annotation is not applying to the sub-resource locator method. This
happens when the name binding annotation is on the resource class or on the sub-resource
locator method. Annotating the sub-resource class or the method within works as expected,
though.
Below is the code needed to reproduce this issue:
{code:java|title=The resource and subresource}
@DemoNameBinding
@Produces(MediaType.APPLICATION_JSON)
@Path("/demo")
public class DemoResource {
@GET
public String getDemoValue() {
return "A value";
}
@Path("/subresource")
public DemoSubResource getSubResource() {
return new DemoSubResource();
}
public class DemoSubResource {
@GET
public String getDemoValue() {
return "A value";
}
}
}
{code}
{code:java|title=The filter}
@Provider
@DemoNameBinding
public class SomeFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext
responseContext) {
responseContext.setEntity("A filtered value");
}
}
{code}
{code:java|title=The binding}
@NameBinding
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface DemoNameBinding {
}
{code}