Search in sources :

Example 1 with Jsonb

use of jakarta.json.bind.Jsonb in project spring-boot by spring-projects.

the class JsonbAutoConfigurationTests method jsonbRegistration.

@Test
void jsonbRegistration() {
    this.contextRunner.run((context) -> {
        assertThat(context).hasSingleBean(Jsonb.class);
        Jsonb jsonb = context.getBean(Jsonb.class);
        assertThat(jsonb.toJson(new DataObject())).isEqualTo("{\"data\":\"hello\"}");
    });
}
Also used : Jsonb(jakarta.json.bind.Jsonb) Test(org.junit.jupiter.api.Test)

Example 2 with Jsonb

use of jakarta.json.bind.Jsonb in project rubia-forums by flashboss.

the class RestCaller method post.

protected static Response post(String url, String authorization, Object entity) {
    Jsonb jsonb = create();
    String json = jsonb.toJson(entity);
    WebTarget target = client.target(url);
    Entity<String> restEntity = entity(json, APPLICATION_JSON);
    return target.request().header("Authorization", authorization).post(restEntity);
}
Also used : Jsonb(jakarta.json.bind.Jsonb) WebTarget(jakarta.ws.rs.client.WebTarget)

Example 3 with Jsonb

use of jakarta.json.bind.Jsonb in project resteasy by resteasy.

the class AbstractJsonBindingProvider method getJsonb.

protected Jsonb getJsonb(Class<?> type) {
    ContextResolver<Jsonb> contextResolver = providers.getContextResolver(Jsonb.class, MediaType.APPLICATION_JSON_TYPE);
    Jsonb delegate = null;
    if (contextResolver != null) {
        delegate = contextResolver.getContext(type);
    }
    return new ManagedJsonb(delegate);
}
Also used : Jsonb(jakarta.json.bind.Jsonb)

Example 4 with Jsonb

use of jakarta.json.bind.Jsonb in project org.openntf.xsp.jakartaee by OpenNTF.

the class JsonGuy method getJson.

public String getJson() {
    TestBean foo = new TestBean();
    foo.setFirstName("foo");
    foo.setLastName("fooson");
    Jsonb jsonb = JsonbBuilder.create();
    return JSONBindUtil.toJson(foo, jsonb);
}
Also used : Jsonb(jakarta.json.bind.Jsonb)

Example 5 with Jsonb

use of jakarta.json.bind.Jsonb in project org.openntf.xsp.jakartaee by OpenNTF.

the class JsonBindingProvider method writeTo.

@Override
public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    Object obj = t;
    // It may be a CDI proxy - try to unwrap it if so
    if (obj instanceof WeldClientProxy) {
        Metadata meta = ((WeldClientProxy) obj).getMetadata();
        obj = meta.getContextualInstance();
    }
    Jsonb jsonb = getJsonb(type);
    JSONBindUtil.toJson(obj, jsonb, entityStream);
    entityStream.flush();
}
Also used : Jsonb(jakarta.json.bind.Jsonb) WeldClientProxy(org.jboss.weld.proxy.WeldClientProxy) Metadata(org.jboss.weld.proxy.WeldClientProxy.Metadata)

Aggregations

Jsonb (jakarta.json.bind.Jsonb)50 Test (org.junit.Test)28 JsonbConfig (jakarta.json.bind.JsonbConfig)12 Test (org.junit.jupiter.api.Test)6 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