◐ Shell
clean mode source ↗

JSON Binding (JSON-B) - Home

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": 4,
    "bitable": false
}