Skip to content

klausboeing/jackson-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages