tree: dbeb939176d73457b6d197e766890cb65c229fb8 [path history] [tgz]
  1. src/
  2. pom.xml
  3. README.MD
examples/entity-filtering/README.MD

Entity Data Filtering

Entity Data Filtering Using custom annotations to filter entities

This example demonstrates how to define custom entity filtering annotations (views) and how to apply them on domain classes as well as on JAX-RS resource classes or JAX-RS resource methods.

The full description how Entity Data Filtering can be found in Jersey User Guide, chapter Entity Data Filtering. Sections relevant to this example (describing this exact example) are:

Contents

The mapping of the URI path space is presented in the following table:

URI pathResource classHTTP methodsAllowed values
/projects/{id}ProjectsResourceGETint
/projectsProjectsResourceGETN/A
/projects/detailed/{id}ProjectsResourceGETint
/projects/detailedProjectsResourceGETN/A
/tasks/{id}?detailed={true|false}TasksResourceGETint, boolean
/tasksTasksResourceGETN/A
/tasks/detailedTasksResourceGETN/A
/users/{id}?detailed={true|false}UsersResourceGETint, boolean
/tasks?detailed={true|false}UsersResourceGETN/A

Application is based on Grizzly container (see App). Everything needed (resources/providers) is registered in EntityFilteringApplication.

Sample Response

Even though the same instance of, e.g. Project class, is used to create response for both basic and detailed view the actual data sent over the wire differ for each of these two views. For basic view it looks like:

{
   "description" : "Jersey is the open source (under dual EPL+GPL license) JAX-RS 2.1 (JSR 370) production quality Reference Implementation for building RESTful Web services.",
   "id" : 1,
   "name" : "Jersey"
}

And for detailed view it looks like:

{
   "description" : "Jersey is the open source (under dual EPL+GPL license) JAX-RS 2.1 (JSR 370) production quality Reference Implementation for building RESTful Web services.",
   "id" : 1,
   "name" : "Jersey",
   "tasks" : [ {
      "description" : "Entity Data Filtering",
      "id" : 1,
      "name" : "ENT_FLT"
   }, {
      "description" : "OAuth 1 + 2",
      "id" : 2,
      "name" : "OAUTH"
   } ],
   "users" : [ {
      "email" : "very@secret.com",
      "id" : 1,
      "name" : "Jersey Robot"
   } ]
}

Running the Example

Run the example as follows:

mvn clean package exec:java

This deploys current example using Grizzly. You can access the application at:

Using Jackson instead of MOXy

This examples uses by default Entity Data Filtering feature together with MOXy. To switch MOXy JSON provider to Jackson (2.x) JSON provider simply

  • comment registration of MOXy ContextResolver, and
    register(new MoxyJsonConfig().setFormattedOutput(true).resolver())
  • uncomment registration of JacksonFeature
    register(JacksonFeature.class)

in EntityFilteringApplication class.