Skip to content

DatatypeFeatures

Tatu Saloranta edited this page Jan 25, 2023 · 1 revision

Jackson on/off features: DatatypeFeatures / DatatypeFeature

As part of Jackson 2.14, a new set of datatype-specific configuration settings was added, as suggested in JSTEP-7.

The idea is to allow easier configuration of more granular settings that affect specific class of data types: both so that:

  1. Settings may be changed on per-call basis
  2. New settings can be added with relative ease in newer versions, with minimal additional plumbing needed.

Each new configuration type is an Enum that implements DatatypeFeature interface.

Configuration is handled using either ObjectMapper.Builder (for ObjectMapper defaults) or ObjectReader.with() (and related) methods:

ObjectMapper mapper = JsonMapper.builder()
    .disable(JsonNodeFeature.READ_NULL_PROPERTIES)
    .build();

ObjectReader r = mapper.readerFor(MyPojo.class)
    .with(JsonNodeFeature.READ_NULL_PROPERTIES);

Configuration types added

Following DatatypeFeature Enums have been added so far (as of Jackson 2.15)

Enum configuration features

EnumFeature was added for Enum-specific configuration.

Tree model (JsonNode) configuration features

JsonNodeFeature was added for configuring handling of Tree Model (JsonNode values), mostly reading and writing.