use of jakarta.json.bind.JsonbConfig in project alias by JohT.
the class ImmutableJsonbConfig method withoutAdapterOfType.
public <T extends JsonbAdapter<?, ?>> JsonbConfig withoutAdapterOfType(Class<T> adapterType) {
JsonbConfig newConfig = getJsonbConfig();
Optional<Object> property = jsonbConfig.getProperty(JsonbConfig.ADAPTERS);
newConfig.setProperty(JsonbConfig.ADAPTERS, withoutType(adapterType, contentsOf(property)).toArray(JsonbAdapter[]::new));
return newConfig;
}
use of jakarta.json.bind.JsonbConfig in project alias by JohT.
the class JsonbConfigProvider method copyOf.
/**
* Creates a defensive copy of {@link JsonbConfig}.
*
* @param config {@link JsonbConfig}
* @return {@link JsonbConfig}
*/
static JsonbConfig copyOf(JsonbConfig config) {
if (config == null) {
return null;
}
JsonbConfig copy = new JsonbConfig();
config.getAsMap().forEach(copy::setProperty);
return copy;
}
use of jakarta.json.bind.JsonbConfig in project annot8 by annot8.
the class Annot8ComponentDescriptorDeserializerTest method testNested.
@Test
public void testNested() {
JsonbConfig config = new JsonbConfig().withDeserializers(new Annot8ComponentDescriptorDeserializer());
Jsonb jb = JsonbBuilder.create(config);
Annot8ComponentDescriptor desc = jb.fromJson("{\"" + Descriptor.class.getName() + "\":{\"name\":\"Test\",\"settings\":{}}}", Annot8ComponentDescriptor.class);
assertEquals(Descriptor.class, desc.getClass());
assertEquals("Test", desc.getName());
assertEquals(Configuration.class, desc.getSettings().getClass());
}
use of jakarta.json.bind.JsonbConfig in project annot8 by annot8.
the class Annot8ComponentDescriptorDeserializerTest method test.
@Test
public void test() {
JsonbConfig config = new JsonbConfig().withDeserializers(new Annot8ComponentDescriptorDeserializer());
Jsonb jb = JsonbBuilder.create(config);
Annot8ComponentDescriptor desc = jb.fromJson("{\"" + TestDescriptor.class.getName() + "\":{\"name\":\"Test\",\"settings\":{\"host\":\"localhost\",\"port\":8080}}}", Annot8ComponentDescriptor.class);
assertEquals(TestDescriptor.class, desc.getClass());
assertEquals("Test", desc.getName());
assertEquals(TestSettings.class, desc.getSettings().getClass());
TestSettings ts = (TestSettings) desc.getSettings();
assertEquals("localhost", ts.getHost());
assertEquals(8080, ts.getPort());
assertEquals(TestProcessor.class, desc.create(null).getClass());
}
use of jakarta.json.bind.JsonbConfig in project annot8 by annot8.
the class Annot8ComponentDescriptorSerializerTest method test.
@Test
public void test() {
JsonbConfig config = new JsonbConfig().withSerializers(new Annot8ComponentDescriptorSerializer());
Jsonb jb = JsonbBuilder.create(config);
String json = jb.toJson(new TestDescriptor("Test", "localhost", 8080));
assertEquals("{\"" + TestDescriptor.class.getName() + "\":{\"name\":\"Test\",\"settings\":{\"host\":\"localhost\",\"port\":8080}}}", json);
}
Aggregations