For questions about Java API for JSON Binding (JSON-B, JSR-367), part of Java EE 8.
From json-b.net:
JSON-B is a standard binding layer for converting Java objects to/from JSON messages. It defines a default mapping algorithm for converting existing Java classes to JSON, while enabling developers to customize the mapping process through the use of Java annotations.
To serialize/deserialize a Java Object to/from JSON
The Java Class
public class Dog { public String name; public int age; public boolean bitable; }
JSON-B API calls
public static void main(String[] args) { // Create a dog instance Dog dog = new Main.Dog(); dog.name = "Falco"; dog.age = 4; dog.bitable = false; // Create Jsonb and serialize Jsonb jsonb = JsonbBuilder.create(); String result = jsonb.toJson(dog); System.out.println(result); // Deserialize back dog = jsonb.fromJson("{\"name\":\"Falco\",\"age\":4,\"bitable\":false}", Dog.class); }
The JSON representation
{ "name": "Falco", "age": 3, "bitable": false }