1. Avaje-JsonB

JSON support using Avaje-JsonB library.

1.1. Usage

1) Add the dependency:

Maven
Gradle
<dependency>
  <groupId>io.jooby</groupId>
  <artifactId>jooby-avaje-jsonb</artifactId>
  <version>3.5.3</version>
</dependency>

2) Install and encode/decode JSON

Java
Kotlin
import io.jooby.avaje.jsonb.AvajeJsonbModule;

{
  install(new AvajeJsonbModule());                  (1)

  get("/", ctx -> {
    MyObject myObject = ...;
    return myObject;                                (2)
  });

  post("/", ctx -> {
    MyObject myObject = ctx.body(MyObject.class);   (3)
    ...
  });
}
1 Install Avaje-JsonB
2 Use Avaje-JsonB to encode arbitrary object as JSON
3 Use Avaje-JsonB to decode JSON to Java object. Client must specify the Content-Type: application/json header

1.2. Working with Jsonb

Access to default Jsonb is available via require call:

Default Jsonb
Java
Kotlin
import io.jooby.avaje.jsonb.AvajeJsonbModule;
import io.avaje.jsonb.Jsonb;

{
  install(new AvajeJsonbModule());

  Jsonb jsonb = require(Jsonb.class);

  ...
}

You can provide your own Jsonb:

Custom Jsonb
Java
Kotlin
import io.jooby.avaje.jsonb.AvajeJsonbModule;
import io.avaje.jsonb.Jsonb;

{
  var jsonb = Jsonb.builder().build();

  install(new AvajeJsonbModule(jsonb));
}