Skip to content

Mapper Features

Tatu Saloranta edited this page Mar 23, 2015 · 19 revisions

Jackson on/off features: MapperFeature

Jackson defines a set of per-mapper configuration, which can ONLY be defined before using ObjectMapper -- meaning that these settings can not be changed on-the-fly, on per-request basis. They configure fundamental POJO introspection details, and resulting built objects (serializers, deserializers, related) are heavily cached. If you need differing settings for these, you have to use separate ObjectMapper instances.

Settings can be divided in couple of loose categories, as follows.

Annotation handling

  • USE_ANNOTATIONS (default: true): whether any annotation processing is used or not -- may be useful on platforms where annotation-processing is hideously expensive

Introspection

  • AUTO_DETECT_CREATORS (default: true)
  • AUTO_DETECT_FIELDS (default: true)
  • AUTO_DETECT_GETTERS (default: true)
  • AUTO_DETECT_IS_GETTERS (default: true)
  • AUTO_DETECT_SETTERS (default: true)
  • REQUIRE_SETTERS_FOR_GETTERS(default: false)
  • USE_GETTERS_AS_SETTERS (default: true)
  • CAN_OVERRIDE_ACCESS_MODIFIERS (default: true)
  • INFER_PROPERTY_MUTATORS (default: true)
    • If enabled, mutators (field or setter used for changing POJO property value) may be inferred: that is, un-annotated, not-visible field or setter can be considered mutator if (and only if!) there is a fully visible or explicitly annotated (@JsonProperty) accessor (getter or field) with same logical name.
    • Enabled by default for convenience: may be disabled if fully explicit annotations are desired.

Name handling

  • SORT_PROPERTIES_ALPHABETICALLY (default: false): Feature that defines default property serialization order used: either alphabetic (true), or "whatever order JDK exposes fields in" (false).
    • Only applies to POJO fields, does not apply to java.util.Map serialization!
    • Note that this is just the default behavior, and can be overridden by explicit overrides in classes, for example with @JsonPropertyOrder
  • USE_WRAPPER_NAME_AS_PROPERTY_NAME (default: false) (since 2.2): Feature that can be enabled to make property names be overridden by wrapper name (usually detected with annotations as defined by {@link AnnotationIntrospector#findWrapperName}. If enabled, all properties that have associated non-empty Wrapper name will use that wrapper name instead of property name.
    • If disabled, wrapper name is only used for wrapping (if anything).
  • ACCEPT_CASE_INSENSITIVE_PROPERTIES (default: false) (since 2.5: Feature that will allow for more forgiving deserialization of incoming JSON: If enabled, the bean properties will be matched using their lower-case equivalents, meaning that any case-combination (incoming and matching names are canonicalized by lower-casing) should work.
    • Note that there is additional performance overhead since incoming property names need to be lower-cased before comparison, for cases where there are upper-case letters. Overhead is more significant if non-lower-case characters are included (i.e. name needs to be changed on the fly)

Other

  • USE_STATIC_TYPING (default: false)
  • DEFAULT_VIEW_INCLUSION (default: true)
Clone this wiki locally