Giter Club home page Giter Club logo

jackson-extension's Introduction

Jackson Extension

Build Status

Module for Jackson adds utilities for serialization and deserialization.

Getting Started

@JsonPropertyGroup and @JsonUsePropertyGroup

Sample 1

public class Customer {

    private String name;
    private String email;
    private String phone;
    private Address address;
    
    // .. more
}
public class Address {

    private String street;
    private String city;
    private String state;
    private String zip;
    private List<Contact> contacts;

    // .. more
}
public class Contact {

    private String name;
    private String email;
    private String phone;
    
    // .. more
}

The JSON result of serialization:

{
  "name" : "Adam Levine",
  "email" : "[email protected]",
  "phone" : "(877) 609-2233",
  "address" : {
    "street" : "1444 S. Alameda Street",
    "city" : "Los Angeles",
    "state" : "Califórnia",
    "zip" : "90021",
    "contacts" : [ {
      "name" : "James Valentine",
      "email" : "[email protected]",
      "phone" : "(877) 609-2244"
    }, {
      "name" : "Jesse Carmichael",
      "email" : "[email protected]",
      "phone" : "(877) 609-2255"
    } ]
  }
}

Use @JsonUsePropertyGroup and @JsonPropertyGroup to reduce serialization of relationships. Note the relationships with @JsonUsePropertyGroup.

public class Customer {

    private String name;
    private String email;
    private String phone;
    
    @JsonUsePropertyGroup
    private Address address;
    
    // .. more
}

Note the attributes of the relationship with @JsonPropertyGroup.

public class Address {

    private String street;
    @JsonPropertyGroup
    private String city;
    @JsonPropertyGroup
    private String state;
    private String zip;
    private List<Contact> contacts;

   // .. more
}

The JSON result of serialization:

{
  "name" : "Adam Levine",
  "email" : "[email protected]",
  "phone" : "(877) 609-2233",
  "address" : {
    "city" : "Los Angeles",
    "state" : "Califórnia"
  }
}

Prerequisities

  • Maven
  • Java 8

Installing

Configure the project repository:

        <repositories>
            <repository>
                <id>klausboeing-mvn-repo</id>
                <url>https://raw.github.com/klausboeing/jackson-extension/mvn-repo/</url>
                <snapshots>
                    <enabled>true</enabled>
                    <updatePolicy>always</updatePolicy>
                </snapshots>
            </repository>
        </repositories>

Add the following dependence on project:

        <dependency>
          <groupId>com.klausboeing</groupId>
          <artifactId>jackson-extension</artifactId>
          <version>0.0.3-SNAPSHOT</version>
        </dependency>

Configure the module in ObjectMapper:

        ObjectMapper om = new ObjectMapper();
        om.registerModule(new JacksonExtensionModule());

Versioning

We use SemVer for versioning.

Authors

  • Klaus Boeing - Initial work

jackson-extension's People

Contributors

klausboeing avatar

Stargazers

Wellington Zomer Nunes avatar Fernando Moraes avatar

Watchers

James Cloos avatar  avatar

Forkers

flaviaguaresi

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.