Skip to content

JSON Features

Tatu Saloranta edited this page Jul 17, 2014 · 8 revisions

Jackson jr: Features

Following is a list of JSON.Feature values available; these can be enabled/disabled by calls to JSON; result is a new JSON object and typical usage is by chaining calls like:

byte[] bytes = JSON.std
    .with(Feature.PRETTY_PRINT_OUTPUT)
    .without(Feature.WRITE_NULL_PROPERTIES)
    .asBytes(bean);

but it is also possible to store and reuse previously configured JSON instances:

JSON configuredJson = JSON.std
    .with(Feature.PRETTY_PRINT_OUTPUT)
    .without(Feature.WRITE_NULL_PROPERTIES);
byte[] bytes = configuredJson.asBytes(bean);

Note that cost of creating new JSON instances is marginal. Also worth noting is that JSON instances are fully immutable, so with() and without() calls never change state of existing instances but create new instances. This means that JSON is fully and completely thread-safe, and usage never needs to be synchronized.

TODO: write descriptions !!!

Writer features

  • WRITE_NULL_PROPERTIES (default: false)
  • WRITE_READONLY_BEAN_PROPERTIES (default: true)
  • WRITE_ENUMS_USING_INDEX (default: false)
  • PRETTY_PRINT_OUTPUT (default: false)
  • FLUSH_AFTER_WRITE_VALUE (default: true)
  • FAIL_ON_UNKNOWN_TYPE_WRITE (default: false)

Reader features

  • USE_BIG_DECIMAL_FOR_FLOATS (default: false)
  • READ_JSON_ARRAYS_AS_JAVA_ARRAYS (default: false)
  • READ_ONLY (default: false)
  • PRESERVE_FIELD_ORDERING (default: true)
  • USE_DEFERRED_MAPS (default: true)
  • USE_IS_SETTERS (default: true)
  • FAIL_ON_DUPLICATE_MAP_KEYS (default: true)
  • FAIL_ON_UNKNOWN_BEAN_PROPERTY (default: false)

Other features

  • HANDLE_JAVA_BEANS (default: true)
  • FORCE_REFLECTION_ACCESS (default: true)
Clone this wiki locally