use of jakarta.json.bind.Jsonb in project org.openntf.xsp.jakartaee by OpenNTF.
the class TestJsonb method testExampleBean.
@Test
public void testExampleBean() {
Jsonb jsonb = JsonbBuilder.create();
ExampleBean bean = new ExampleBean();
bean.setFoo("hello");
bean.setBar("world");
String json = JSONBindUtil.toJson(bean, jsonb);
assertEquals("Serialized bean should match expected", "{\"bar\":\"world\",\"foo\":\"hello\"}", json);
ExampleBean bean2 = JSONBindUtil.fromJson(json, jsonb, ExampleBean.class);
assertEquals("Beans should be equivalent", bean, bean2);
}
use of jakarta.json.bind.Jsonb in project zilla by aklivity.
the class ZpmSettingsTest method shouldWriteCredential.
@Test
public void shouldWriteCredential() {
String expected = "{" + "\"credentials\":" + "[" + "{" + "\"host\":\"repo1.maven.org\"," + "\"password\":\"pass\"," + "\"realm\":\"HTTP Realm\"," + "\"username\":\"user\"" + "}" + "]" + "}";
ZpmSettings settings = new ZpmSettings();
settings.credentials = Collections.singletonList(new ZpmCredentials("HTTP Realm", "repo1.maven.org", "user", "pass"));
Jsonb builder = JsonbBuilder.create();
String actual = builder.toJson(settings);
assertEquals(expected, actual);
}
use of jakarta.json.bind.Jsonb in project zilla by aklivity.
the class ZpmSettingsTest method shouldReadCredentials.
@Test
public void shouldReadCredentials() {
String text = "{" + "\"credentials\":" + "[" + "{" + "\"realm\": \"HTTP Realm\"," + "\"host\": \"repo1.maven.org\"," + "\"username\": \"user\"," + "\"password\": \"pass\"" + "}," + "{" + "\"realm\": \"HTTP Realm 2\"," + "\"host\": \"repo2.maven.org\"," + "\"username\": \"user2\"," + "\"password\": \"pass2\"" + "}" + "]" + "}";
Jsonb builder = JsonbBuilder.create();
ZpmSettings settings = builder.fromJson(text, ZpmSettings.class);
assertThat(settings, not(nullValue()));
assertThat(settings.credentials, not(nullValue()));
assertThat(settings.credentials, equalTo(asList(new ZpmCredentials("HTTP Realm", "repo1.maven.org", "user", "pass"), new ZpmCredentials("HTTP Realm 2", "repo2.maven.org", "user2", "pass2"))));
}
use of jakarta.json.bind.Jsonb in project zilla by aklivity.
the class ZpmConfigurationTest method shouldWriteRepositories.
@Test
public void shouldWriteRepositories() {
String expected = "{" + "\"repositories\":" + "[" + "\"https://maven.example.com/maven2/\"," + "\"https://repo1.maven.org/maven2/\"" + "]" + "}";
ZpmConfiguration config = new ZpmConfiguration();
config.repositories = Arrays.asList(new ZpmRepository("https://maven.example.com/maven2/"), new ZpmRepository("https://repo1.maven.org/maven2/"));
Jsonb builder = JsonbBuilder.create();
String actual = builder.toJson(config);
assertEquals(expected, actual);
}
use of jakarta.json.bind.Jsonb in project zilla by aklivity.
the class ZpmConfigurationTest method shouldReadDependency.
@Test
public void shouldReadDependency() {
String text = "{" + "\"dependencies\":" + "[" + "\"io.aklivity.zilla:engine:1.0.0\"" + "]" + "}";
Jsonb builder = JsonbBuilder.create();
ZpmConfiguration config = builder.fromJson(text, ZpmConfiguration.class);
assertThat(config, not(nullValue()));
assertThat(config.dependencies, equalTo(singletonList(new ZpmDependency("io.aklivity.zilla", "engine", "1.0.0"))));
}
Aggregations