Module for Jackson adds utilities for serialization and deserialization.
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"
}
}
- Maven
- Java 8
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());
We use SemVer for versioning.
- Klaus Boeing - Initial work