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

Entity Data Filtering Dynamic and Configurable Query Parameters

This example demonstrates how to use entity filtering feature dynamically with defining what should be sent to the other side based on query parameters and how to apply the rules 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 valuesNotes
/people/{id}?select={select}PersonResourceGETid = any value, select = field names from Person/Address/PhoneNumber classReturns fields of Person/Address/PhoneNumber
/people/{id}/addresses?select={select}PersonResourceGETid = any value, select = field names from Address/PhoneNumber classReturns fields of Address/PhoneNumber

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

Sample Response

Even though the same instance of, e.g. Person class, is used to create response the given values of select query parameter are used to select the fields that would be transferred over the wire. For people/1234?select=familyName,givenName it looks like:

{
   "familyName": "Dowd",
   "givenName": "Andrew"
}

And for people/1234?select=familyName,givenName,addresses.phoneNumber.number it looks like:

{
   "addresses":[
      {
         "phoneNumber":{
            "number": "867-5309"
         }
      }
   ],
   "familyName": "Dowd",
   "givenName": "Andrew"
}

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 SelectableEntityFilteringApplication class.