Skip to content

Instantly share code, notes, and snippets.

@gtudan
Last active November 19, 2018 09:49
Show Gist options
  • Save gtudan/77a942873260756c912aad9c2fb947fa to your computer and use it in GitHub Desktop.
Save gtudan/77a942873260756c912aad9c2fb947fa to your computer and use it in GitHub Desktop.
Customizing JSON-B output using Config
var config = new JsonbConfig()
.withFormatting(true) // indents the output - default is false
.withNullValues(true); // show null fields - default is false
var jsonb = JsonbBuilder.create(config);
var json = jsonb.toJson(new Greeting("Hello World!"));
System.out.println(json);
/*
{
"created": "2018-11-18",
"greeting": "Hello World!"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment