Using the JSR 367 – Java API for JSON Binding
Using the JSR 367 – Java API for JSON Binding
Similar to JAXB for XML processing, the JSR 367: Java API for JSON Binding(JSON-B) defines the binding layer for transforming Java objects to JSON messages and vice-versa, as depicted ahead:

Now let's look at the key components of JSON-B:
Class or Interface | Description | |||
javax.json.bind.Jsonb | This is the core API that provides the functions to serialize a Java object to JSON and deserialize to Java object from a JSON input. | |||
javax.json.bind.JsonbConfig | This class provides functions for formatting and encoding to create customized JSON data. | |||
javax.json.bind.JsonbBuilder | As the name suggests, this API abstracts the creation of JSON-B instances for the specified configuration or provider. | |||
Processing JSON using JSON-BThe following example reads the JSON representation of the Employee object from the emp.json file and uses the javax.json.bind.JsonBuilder to create an instance of javax.json.bind.Jsonb to map the Employee object to JSON representation and vice-versa:
The implementation of the preceding steps is demonstrated in the following program: The preceding program reads the emp.json file and prints the Employee object and JSON, as shown ahead: |
Comments
Post a Comment