Search in sources :

Example 41 with JsonbConfig

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;
}
Also used : JsonbConfig(jakarta.json.bind.JsonbConfig) JsonbAdapter(jakarta.json.bind.adapter.JsonbAdapter)

Example 42 with JsonbConfig

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;
}
Also used : JsonbConfig(jakarta.json.bind.JsonbConfig)

Example 43 with JsonbConfig

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());
}
Also used : JsonbConfig(jakarta.json.bind.JsonbConfig) Jsonb(jakarta.json.bind.Jsonb) Annot8ComponentDescriptor(io.annot8.api.components.Annot8ComponentDescriptor) Annot8ComponentDescriptor(io.annot8.api.components.Annot8ComponentDescriptor) Descriptor(io.annot8.common.serialization.TestNested.Descriptor) Test(org.junit.jupiter.api.Test)

Example 44 with JsonbConfig

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());
}
Also used : JsonbConfig(jakarta.json.bind.JsonbConfig) Jsonb(jakarta.json.bind.Jsonb) Annot8ComponentDescriptor(io.annot8.api.components.Annot8ComponentDescriptor) Test(org.junit.jupiter.api.Test)

Example 45 with JsonbConfig

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);
}
Also used : JsonbConfig(jakarta.json.bind.JsonbConfig) Jsonb(jakarta.json.bind.Jsonb) Test(org.junit.jupiter.api.Test)

Aggregations

JsonbConfig (jakarta.json.bind.JsonbConfig)45 Before (org.junit.Before)28 Jsonb (jakarta.json.bind.Jsonb)12 Test (org.junit.jupiter.api.Test)5 InputStream (java.io.InputStream)4 Files.newInputStream (java.nio.file.Files.newInputStream)3 Path (java.nio.file.Path)3 ZpmSecurity (io.aklivity.zilla.manager.internal.settings.ZpmSecurity)2 Annot8ComponentDescriptor (io.annot8.api.components.Annot8ComponentDescriptor)2 Descriptor (io.annot8.common.serialization.TestNested.Descriptor)2 OutputStream (java.io.OutputStream)2 Files.newOutputStream (java.nio.file.Files.newOutputStream)2 ZpmCredentials (io.aklivity.zilla.manager.internal.settings.ZpmCredentials)1 ZpmSettings (io.aklivity.zilla.manager.internal.settings.ZpmSettings)1 Engine (io.aklivity.zilla.runtime.engine.Engine)1 EngineConfiguration (io.aklivity.zilla.runtime.engine.EngineConfiguration)1 BindingConfig (io.aklivity.zilla.runtime.engine.config.BindingConfig)1 NamespaceConfig (io.aklivity.zilla.runtime.engine.config.NamespaceConfig)1 RouteConfig (io.aklivity.zilla.runtime.engine.config.RouteConfig)1 VaultConfig (io.aklivity.zilla.runtime.engine.config.VaultConfig)1