Package jakarta.ws.rs

Annotation Interface BeanParam


@Target({PARAMETER,METHOD,FIELD}) @Retention(RUNTIME) @Documented @Qualifier public @interface BeanParam
The annotation that may be used to inject custom JAX-RS "parameter aggregator" value object into a resource class field, property or resource method parameter.

When running with an active CDI container, the bean is created and injected by CDI like any other CDI-managed type: fields and properties annotated with @Inject are injected normally, and fields and properties annotated with one of the @XxxParam annotations (@PathParam, @FormParam ...) are resolved from the current request context using the same CDI qualifier mechanism used for resource method parameters.

Without an active CDI container, the JAX-RS runtime instantiates the object and injects all its fields and properties annotated with one of the @XxxParam annotations. For the POJO classes the same instantiation and injection rules apply as in the case of instantiation and injection of request-scoped root resource classes.

For example:
 public class MyBean {
   @FormParam("myData")
   private String data;

   @HeaderParam("myHeader")
   private String header;

   @PathParam("id")
   public void setResourceId(String id) {...}

   ...
 }

 @Path("myresources")
 public class MyResources {
   @POST
   @Path("{id}")
   public void post(@BeanParam MyBean myBean) {...}

   ...
 }
 

Because injection occurs at object creation time, use of this annotation on resource class fields and bean properties is only supported for the default per-request resource class lifecycle. Resource classes using other lifecycles should only use this annotation on resource method parameters.

Since:
2.0
Author:
Marek Potociar
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Supports inline instantiation of the BeanParam annotation.