gson

gson

JSON support via Gson library.

exports

dependency

<dependency>
  <groupId>org.jooby</groupId>
  <artifactId>jooby-gson</artifactId>
  <version>1.6.6</version>
</dependency>

usage

import org.jooby.json.Gzon;

{
  use(new Gzon());
 
  // 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 Gson
  get("/access", req -> {
    Gson gson = require(Gson.class);
    // ...
  });
}

configuration

If you need a special setting or configuration for your Gson:

{
  use(new Gzon().doWith(builder -> {
    builder.setPrettyPrint();
    // ...
  });
}