Formatting output
Some configuration parameters can be used to change the behavior of the JSON serialization/deserialization process. This is done by passing a JSONÂ config
object to the create
method of the JsonBuilder
class. The configuration object is used to hold some configuration metadata, which the jsonb
object will be used during serialization/deserialization.
In the following example, we will create a JSON config
object to be used within the jsonb
object:
// Instantiate a custom JSON-B configuration object JsonbConfig config = new JsonbConfig(); // Instantiate a JSON-B object with our custom configuration Jsonb jsonb = JsonbBuilder.create(config);
We have not performed any changes to the default configuration values of the jsonb
configuration object. Now, let's enable one of the pretty features of jsonb
, which is the formatting option.
The formatting option is used to format the output JSON, so that it's displayed with hierarchy and indentation to make it more readable by humans...