use of javax.json.bind.JsonbConfig in project tutorials by eugenp.
the class JsonbTest method givenPersonObject_whenNamingStrategy_thenGetCustomPersonJson.
@Test
public void givenPersonObject_whenNamingStrategy_thenGetCustomPersonJson() {
JsonbConfig config = new JsonbConfig().withPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CASE_WITH_UNDERSCORES);
Jsonb jsonb = JsonbBuilder.create(config);
Person person = new Person(1, "Jhon", "jhon@test.com", 20, LocalDate.of(2019, 9, 7), BigDecimal.valueOf(1000));
String jsonPerson = jsonb.toJson(person);
// @formatter:off
String jsonExpected = "{\"email\":\"jhon@test.com\"," + "\"id\":1," + "\"person-name\":\"Jhon\"," + "\"registered_date\":\"07-09-2019\"," + "\"salary\":\"1000.0\"}";
// @formatter:on
assertTrue(jsonExpected.equals(jsonPerson));
}
use of javax.json.bind.JsonbConfig in project component-runtime by Talend.
the class UiSpecServiceTest method out.
/*
* just to log the output
*/
@Test
@Disabled("debug test to log the produced model")
void out() throws Exception {
final Ui payload = service.convert(load("jdbc.json")).toCompletableFuture().get();
System.out.println(JsonbBuilder.create(new JsonbConfig().withFormatting(true)).toJson(payload));
}
use of javax.json.bind.JsonbConfig in project tutorials by eugenp.
the class JsonbTest method givenPersonObject_whenWithPropertyOrderStrategy_thenGetReversePersonJson.
@Test
public void givenPersonObject_whenWithPropertyOrderStrategy_thenGetReversePersonJson() {
JsonbConfig config = new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.REVERSE);
Jsonb jsonb = JsonbBuilder.create(config);
Person person = new Person(1, "Jhon", "jhon@test.com", 20, LocalDate.of(2019, 9, 7), BigDecimal.valueOf(1000));
String jsonPerson = jsonb.toJson(person);
// @formatter:off
String jsonExpected = "{\"salary\":\"1000.0\"," + "\"registeredDate\":\"07-09-2019\"," + "\"person-name\":\"Jhon\"," + "\"id\":1," + "\"email\":\"jhon@test.com\"}";
// @formatter:on
assertTrue(jsonExpected.equals(jsonPerson));
}
use of javax.json.bind.JsonbConfig 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 javax.json.bind.JsonbConfig 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