Skip to content

Instantly share code, notes, and snippets.

@gtudan
Created November 18, 2018 15:45
Show Gist options
  • Save gtudan/3440d0633b8cea05ccfbdbad3b5481ed to your computer and use it in GitHub Desktop.
Save gtudan/3440d0633b8cea05ccfbdbad3b5481ed to your computer and use it in GitHub Desktop.
To JSON and back again using JSON-B
import javax.json.bind.*;
/* ... */
var pojo = new Greeting("Hello World!");
// to JSON
Jsonb jsonb = JsonbBuilder.create();
String json = jsonb.toJson(pojo);
assertEquals("{\"greeting\":\"Hello World!\"}", json);
// and back again
var pojo2 = jsonb.fromJson(json, Greeting.class);
assertEquals(pojo, pojo2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment