use of com.baeldung.adapter.PersonAdapter in project tutorials by eugenp.
the class JsonbTest method givenPersonJson_whenDeserializeWithAdapter_thenGetPersonObject.
@Test
public void givenPersonJson_whenDeserializeWithAdapter_thenGetPersonObject() {
JsonbConfig config = new JsonbConfig().withAdapters(new PersonAdapter());
Jsonb jsonb = JsonbBuilder.create(config);
// new Person(1, "Jhon");
Person person = new Person(1, "Jhon", "jhon@test.com", 0, LocalDate.of(2019, 9, 7), BigDecimal.valueOf(1000.0));
// @formatter:off
String jsonPerson = "{\"id\":1," + "\"name\":\"Jhon\"}";
// @formatter:on
assertTrue(jsonb.fromJson(jsonPerson, Person.class).equals(person));
}
use of com.baeldung.adapter.PersonAdapter in project tutorials by eugenp.
the class JsonbTest method givenPersonObject_whenSerializeWithAdapter_thenGetPersonJson.
@Test
public void givenPersonObject_whenSerializeWithAdapter_thenGetPersonJson() {
JsonbConfig config = new JsonbConfig().withAdapters(new PersonAdapter());
Jsonb jsonb = JsonbBuilder.create(config);
// new Person(1, "Jhon");
Person person = new Person(1, "Jhon", "jhon@test.com", 0, LocalDate.of(2019, 9, 7), BigDecimal.valueOf(1000.0));
String jsonPerson = jsonb.toJson(person);
// @formatter:off
String jsonExpected = "{\"id\":1," + "\"name\":\"Jhon\"}";
// @formatter:on
assertTrue(jsonExpected.equals(jsonPerson));
}
Aggregations