I have the same problem and tried Zero3's solution (Required @QueryParam in JAX-RS (and what to do in their absence)), but in my case parameter.isAnnotationPresent(Required.class)
always return false
.
This is my Required annotation:
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Required {
// This is just a marker annotation, so nothing in here.
}
I also tried it with a BeanParam
annotation and modified the filter accordingly, but same result - always get null
for isAnnotionPresen
.
I'm using WildFly 9 (RESTeasy) which automatically registers the request filter.
My REST resource looks like this:
@GET
@Path("/{type}/{id}")
public Response getAllByTypeAndId(@Required @BeanParam RequiredQueryParams requiredQueryParams,
@Required @QueryParam("mandant") String mandant,
@PathParam("type") String type,
@PathParam("id") Long id) {
...doSomething...
}
Running the debugger shows for parameter.declaredAnnotations two entries in the HashMap for BeanParam
:
0 interface my.annotations.Required -> @my.annotations.Required()
1 interface javax.ws.rs.BeanParam -> @javax.ws.rs.BeanParam()
and for QueryParam
:
0 interface my.annotations.Required -> @my.annotations.Required()
1 interface javax.ws.rs.QueryParam -> @javax.ws.rs.QueryParam(value=mandant)
Any hints welcome - Thank you!