Giter Site home page Giter Site logo

jackson-jaxrs-propertyfiltering's Introduction

jackson-jaxrs-propertyfiltering Build Status

Overview

Library to enable automatic filtering of JSON responses from JAX-RS endpoints. Clients specify via query params what properties they want and the library handles filtering the response entities down to just those properties (see here for some examples). Tested with Jersey but should work with any JAX-RS implementation.

Maven dependency

To use module on Maven-based projects, use following dependency:

<dependency>
  <groupId>com.hubspot.jackson</groupId>
  <artifactId>jackson-jaxrs-propertyfiltering</artifactId>
  <version>0.8.4</version>
</dependency>

(or whatever version is most up-to-date at the moment)

Configuration

  1. Register PropertyFilteringMessageBodyWriter with your JAX-RS implementation
  2. Annotate the desired endpoints with @PropertyFiltering
  3. Profit

Yes, it's just that simple.

Usage

Let's assume you have an endpoint annotated with @PropertyFiltering that returns JSON of the form:

{
  "id": 54,
  "name": "Object",
  "child": {
    "id": 96,
    "name": "Child Object"
  }
}

If you just need the id field you can pass ?property=id which will return:

{
  "id": 54
}

Nested fields are also supported with dot-notation, so if you need the child id as well, you can pass ?property=id&property=child.id which will return:

{
  "id": 54,
  "child": {
    "id": 96
  }
}

You can also specify fields by exclusion rather than inclusion, so if you don't need the child field but want everything else you can pass ?property=!child which will return:

{
  "id": 54,
  "name": "Object"
}

jackson-jaxrs-propertyfiltering's People

Contributors

boulter avatar hs-jenkins-bot avatar jboulter avatar jhaber avatar kartoffel17 avatar maddoc42 avatar snappiet avatar stevie400 avatar tpetr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.