Skip to content

Configuration

Glythcing edited this page Sep 17, 2018 · 1 revision

Underlying JSON Library

Tranquil wraps a JSON de/serialization library for:

  • Converting user supplied JSON into the internal structure (a Map) on which it operates
  • Converting the predicated / projected response into the user's desired output

Two libraries are supported:

  • Jackson, this is the default
  • Gson

Tranquil allows these to be configured as follows:

// this is equivalent to the default behaviour
Tranquil.using(new JacksonMappingProvider())
  .parse(json)
  .read(select, where)

// use the default Gson mapper
Tranquil.using(new GsonMappingProvider())
  .parse(json)
  .read(select, where)

// use a custom Jackson object mapper
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
Tranquil.using(new JacksonMappingProvider(objectMapper))
  .parse(json)
  .read(select, where)

// use a custom Gson instance
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Tranquil.using(new GsonMappingProvider(gson))
  .parse(json)
  .read(select, where)

So, since you can supply your own ObjectMapper or Gson instance you can control the underlying JSON library's behaviour.

Options

The Tranquil instance can be created with a Configuration instance which encapsulates the library's runtime options. For example:

// suppress any exceptions encountered when parsing or reading
Tranquil.using(Configuration.builder().options(Options.SUPPRESS_EXCEPTIONS).build())
  .parse(json)
  .read(select, where)