VOOZH about

URL: https://www.javacodegeeks.com/2018/08/json-b-asymmetrical-property-binding.html

⇱ JSON-B Asymmetrical Property Binding - Java Code Geeks


The JSON-B specification defines binding annotations such as @JsonbProperty or @JsonbTransient to declaratively map Java objects to JSON, and back. These annotations can be used β€˜asymmetrically’ to define different handling of serialization and deserialization.

If JSON Binding annotations are annotated on Java properties, or on both getters and setters, they will control how the objects are serialized and deserialized. If they are only defined on either the getter or the setter, the behavior will only take action for either serialization or deserialization, respectively. The binding definitions for multiple properties can be mixed and matched within a single class.

See the following example:

public class Account {

 private long id;

 // will always map name to testName
 @JsonbProperty("testName")
 private String name;

 // will serialize id to JSON
 public long getId() {
 return id;
 }

 // will not deserialize id from JSON
 @JsonbTransient
 public void setId(long id) {
 this.id = id;
 }

 public String getName() {
 return name;
 }

 public void setName(String name) {
 this.name = name;
 }
}

Happy asymmetrical JSON binding!

Published on Java Code Geeks with permission by Sebastian Daschner, partner at our JCG program. See the original article here: JSON-B Asymmetrical Property Binding

Opinions expressed by Java Code Geeks contributors are their own.

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

Tags
JSON
πŸ‘ Photo of Sebastian Daschner
Sebastian Daschner
August 21st, 2018Last Updated: August 21st, 2018
0 72 1 minute read

Sebastian Daschner

Sebastian Daschner is a self-employed Java consultant and trainer. He is the author of the book 'Architecting Modern Java EE Applications'. Sebastian is a Java Champion, Oracle Developer Champion and JavaOne Rockstar.
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz