Created
November 18, 2018 15:45
-
-
Save gtudan/3440d0633b8cea05ccfbdbad3b5481ed to your computer and use it in GitHub Desktop.
To JSON and back again using JSON-B
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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