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\"}");
});
}
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);
}
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);
}
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);
}
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();
}
Aggregations