Annotation Type EntityFiltering


@Target(ANNOTATION_TYPE) @Retention(RUNTIME) @Documented public @interface EntityFiltering
Meta-annotation used to create entity filtering annotations for entity (model) classes and resource methods and resources.

Entity Data Filtering via annotations is supposed to be used to annotate:

  • entity classes (supported on both, server and client sides), and
  • resource methods / resource classes (server side)

In entity filtering, a entity-filtering annotation is first defined using the @EntityFiltering meta-annotation:

  @Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD })
  @Retention(value = RetentionPolicy.RUNTIME)
  @EntityFiltering
  public @interface DetailedView {

      public static class Factory extends AnnotationLiteral<DetailedView> implements DetailedView {

         public static DetailedView get() {
               return new Factory();
           }
      }
  }
 

Entity-filtering annotation should provide a factory class/method to create an instance of the annotation. Example of such factory can be seen in the DetailedView above. Such instances can be then passed to the client/server runtime to define/override entity-filtering scopes.

The defined entity-filtering annotation is then used to decorate a entity, it's property accessors or fields (more than one entity may be decorated with the same entity-filtering annotation):

  public class MyEntityClass {

      @DetailedView
      private String myField;

      ...
  }
 

At last, on the server-side, the entity-filtering annotations are applied to the resource or resource method(s) to which the entity-filtering should be applied:

  @Path("/")
  public class MyResourceClass {

      @GET
      @Produces("text/plain")
      @Path("{id}")
      @DetailedView
      public MyEntityClass get(@PathParam("id") String id) {
          // Return MyEntityClass.
      }
  }
 

At last, on the client-side, the entity-filtering annotations are passed to the runtime via Entity.entity() method and the entity-filtering scopes are then derived from the annotations:

  ClientBuilder.newClient()
      .target("resource")
      .request()
      .post(Entity.entity(myentity, "application/json", new Annotation[] {MyEntityClass.Factory.get()}));