public class Yasson extends Object implements Jooby.Module
{
use(new Yasson());
// sending
get("/my-api", req -> new MyObject());
// receiving a json body
post("/my-api", req -> {
MyObject obj = req.body(MyObject.class);
return obj;
});
// direct access to Jsonb
get("/access", req -> {
Jsonb jsonb = req.require(Jsonb.class);
// ...
});
}
If you need a special setting or configuration for your Jsonb:
{
use(new Yasson().doWith(builder -> {
builder.withFormatting(true);
// ...
});
}
| Constructor and Description |
|---|
Yasson()
Creates a new
Jsonb and set type to: MediaType.json. |
Yasson(MediaType type)
Creates a new
Jsonb. |
| Modifier and Type | Method and Description |
|---|---|
void |
configure(Env env,
com.typesafe.config.Config config,
com.google.inject.Binder binder) |
Yasson |
doWith(BiConsumer<javax.json.bind.JsonbConfig,com.typesafe.config.Config> configurer)
Configurer callback.
|
Yasson |
doWith(Consumer<javax.json.bind.JsonbConfig> configurer)
Configurer callback.
|
Yasson |
raw()
Add support raw string json responses:
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconfigpublic Yasson()
Jsonb and set type to: MediaType.json.public Yasson doWith(BiConsumer<javax.json.bind.JsonbConfig,com.typesafe.config.Config> configurer)
{
use(new Yasson().doWith(builder -> {
builder.withFormatting(true);
// ...
});
}
configurer - A callback.public Yasson doWith(Consumer<javax.json.bind.JsonbConfig> configurer)
{
use(new Yasson().doWith((builder, config) -> {
builder.withFormatting(true);
// ...
});
}
configurer - A callback.public void configure(Env env, com.typesafe.config.Config config, com.google.inject.Binder binder)
configure in interface Jooby.Modulepublic Yasson raw()
{
get("/raw", () -> {
return "{\"raw\": \"json\"}";
});
}
Copyright © 2021. All rights reserved.