Skip to content
Eclipse Project for JSON-B
Branch: master
Clone or download
Latest commit 9f3f0c4 Mar 5, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
etc/config NOTICE and CONTRIBUTING files added Jul 17, 2018 Initial contribution May 25, 2018 NOTICE and CONTRIBUTING files added Jul 17, 2018 Update readme Mar 8, 2019

Java API for JSON Binding (JSON-B)

Maven Central License

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.

Get it


<!-- -->

Mapping a simple class

Suppose we have the following Java object, which we want to represent with JSON data:

public class User {
  public long id;
  public String name;
  public int age;

Using the default mapping, this class can be serialized (as-is) to a JSON string:

Jsonb jsonb = JsonbBuilder.create();

User bob = new User(); = 1234; = "Bob";
bob.age = 42;

String bobJson = jsonb.toJson(bob);
System.out.println(bobJson); // {"id":1234,"name":Bob","age":42}

Likewise, JSON data can be deserialized back into Java objects:

Jsonb jsonb = JsonbBuilder.create();

String aliceJson = "{\"id\":5678,\"name\":Alice\",\"age\":42}";
User alice = jsonb.fromJson(aliceJson, User.class);


You can’t perform that action at this time.