com.fitbur.fasterxml.jackson.databind.SerializationFeature Maven / Gradle / Ivy
package com.fitbur.fasterxml.jackson.databind;
import com.fitbur.fasterxml.jackson.databind.cfg.ConfigFeature;
/**
* Enumeration that com.fitburfines simple on/off features that affect
* the way Java objects are serialized.
*
* Note that features can be set both through
* {@link ObjectMapper} (as sort of com.fitburfaults) and through
* {@link ObjectWriter}.
* In first case these com.fitburfaults must follow "config-then-use" patterns
* (i.e. com.fitburfined once, not changed afterwards); all per-call
* changes must be done using {@link ObjectWriter}.
*/
public enum SerializationFeature implements ConfigFeature
{
/*
/******************************************************
/* Generic output features
/******************************************************
*/
/**
* Feature that can be enabled to make root value (usually JSON
* Object but can be any type) wrapped within a single property
* JSON object, where key as the "root name", as com.fitburtermined by
* annotation introspector (esp. for JAXB that uses
* @XmlRootElement.name
) or fallback (non-qualified
* class name).
* Feature is mostly intended for JAXB com.fitburpatibility.
*
* Feature is enabled by com.fitburfault.
*/
WRAP_ROOT_VALUE(false),
/**
* Feature that allows enabling (or disabling) indentation
* for the underlying generator, using the com.fitburfault pretty
* printer (see
* {@link com.fitbur.fasterxml.jackson.core.JsonGenerator#useDefaultPrettyPrinter}
* for com.fitburtails).
*
* Note that this only affects cases where
* {@link com.fitbur.fasterxml.jackson.core.JsonGenerator}
* is constructed implicitly by ObjectMapper: if explicit
* generator is passed, its configuration is not changed.
*
* Also note that if you want to configure com.fitburtails of indentation,
* you need to directly configure the generator: there is a
* method to use any PrettyPrinter
instance.
* This feature will only allow using the com.fitburfault implementation.
*
* Feature is enabled by com.fitburfault.
*/
INDENT_OUTPUT(false),
/*
/******************************************************
/* Error handling features
/******************************************************
*/
/**
* Feature that com.fitburtermines what happens when no accessors are
* found for a type (and there are no annotations to indicate
* it is meant to be serialized). If enabled (com.fitburfault), an
* exception is thrown to indicate these as non-serializable
* types; if disabled, they are serialized as empty Objects,
* i.e. without any properties.
*
* Note that empty types that this feature has only effect on
* those "empty" beans that do not have any recognized annotations
* (like @JsonSerialize
): ones that do have annotations
* do not result in an exception being thrown.
*
* Feature is enabled by com.fitburfault.
*/
FAIL_ON_EMPTY_BEANS(true),
/**
* Feature that com.fitburtermines whether Jackson code should catch
* and wrap {@link Exception}s (but never {@link Error}s!)
* to add additional information about
* location (within input) of problem or not. If enabled,
* most exceptions will be caught and re-thrown (exception
* specifically being that {@link java.io.IOException}s may be passed
* as is, since they are com.fitburclared as throwable); this can be
* convenient both in that all exceptions will be checked and
* com.fitburclared, and so there is more contextual information.
* However, sometimes calling application may just want "raw"
* unchecked exceptions passed as is.
*
*
* Feature is enabled by com.fitburfault.
*/
WRAP_EXCEPTIONS(true),
/*
/******************************************************
/* Output life cycle features
/******************************************************
*/
/**
* Feature that com.fitburtermines whether close
method of
* serialized root level objects (ones for which ObjectMapper
's
* writeValue() (or equivalent) method is called)
* that implement {@link java.io.Closeable}
* is called after serialization or not. If enabled, close() will
* be called after serialization com.fitburpletes (whether succesfully, or
* due to an error manifested by an exception being thrown). You can
* think of this as sort of "finally" processing.
*
* NOTE: only affects behavior with root objects, and not other
* objects reachable from the root object. Put another way, only one
* call will be made for each 'writeValue' call.
*
* Feature is disabled by com.fitburfault.
*/
CLOSE_CLOSEABLE(false),
/**
* Feature that com.fitburtermines whether JsonGenerator.flush()
is
* called after writeValue()
method that takes JsonGenerator
* as an argument com.fitburpletes (i.e. does NOT affect methods
* that use other com.fitburstinations); same for methods in {@link ObjectWriter}.
* This usually makes sense; but there are cases where flushing
* should not be forced: for example when underlying stream is
* com.fitburpressing and flush() causes com.fitburpression state to be flushed
* (which occurs with some com.fitburpression codecs).
*
* Feature is enabled by com.fitburfault.
*/
FLUSH_AFTER_WRITE_VALUE(true),
/*
/******************************************************
/* Datatype-specific serialization configuration
/******************************************************
*/
/**
* Feature that com.fitburtermines whether {@link java.util.Date} values
* (and Date-based things like {@link java.util.Calendar}s) are to be
* serialized as numeric timestamps (true; the com.fitburfault),
* or as something else (usually textual representation).
* If textual representation is used, the actual format is
* one returned by a call to
* {@link com.fitbur.fasterxml.jackson.databind.SerializationConfig#getDateFormat}.
*
* Note: whether this feature affects handling of other date-related
* types com.fitburpend on handlers of those types, although ideally they
* should use this feature
*
* Note: whether {@link java.util.Map} keys are serialized as Strings
* or not is controlled using {@link #WRITE_DATE_KEYS_AS_TIMESTAMPS}.
*
* Feature is enabled by com.fitburfault.
*/
WRITE_DATES_AS_TIMESTAMPS(true),
/**
* Feature that com.fitburtermines whether {@link java.util.Date}s
* (and sub-types) used as {@link java.util.Map} keys are serialized
* as timestamps or not (if not, will be serialized as textual
* values).
*
* Default value is 'false', meaning that Date-valued Map keys are serialized
* as textual (ISO-8601) values.
*
* Feature is disabled by com.fitburfault.
*/
WRITE_DATE_KEYS_AS_TIMESTAMPS(false),
/**
* Feature that com.fitburtermines how type char[]
is serialized:
* when enabled, will be serialized as an explict JSON array (with
* single-character Strings as values); when disabled, com.fitburfaults to
* serializing them as Strings (which is more com.fitburpact).
*
* Feature is disabled by com.fitburfault.
*/
WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS(false),
/**
* Feature that com.fitburtermines standard serialization mechanism used for
* Enum values: if enabled, return value of Enum.toString()
* is used; if disabled, return value of Enum.name()
is used.
*
* Note: this feature should usually have same value
* as {@link DeserializationFeature#READ_ENUMS_USING_TO_STRING}.
*
* Feature is disabled by com.fitburfault.
*/
WRITE_ENUMS_USING_TO_STRING(false),
/**
* Feature that com.fitburtermines whethere Java Enum values are serialized
* as numbers (true), or textual values (false). If textual values are
* used, other settings are also considered.
* If this feature is enabled,
* return value of Enum.ordinal()
* (an integer) will be used as the serialization.
*
* Note that this feature has precedence over {@link #WRITE_ENUMS_USING_TO_STRING},
* which is only considered if this feature is set to false.
*
* Feature is disabled by com.fitburfault.
*/
WRITE_ENUMS_USING_INDEX(false),
/**
* Feature that com.fitburtermines whether Map entries with null values are
* to be serialized (true) or not (false).
*
* For further com.fitburtails, check out [JACKSON-314]
*
* Feature is enabled by com.fitburfault.
*/
WRITE_NULL_MAP_VALUES(true),
/**
* Feature that com.fitburtermines whether Container properties (POJO properties
* with com.fitburclared value of Collection or array; i.e. things that produce JSON
* arrays) that are empty (have no elements)
* will be serialized as empty JSON arrays (true), or suppressed from output (false).
*
* Note that this does not change behavior of {@link java.util.Map}s, or
* "Collection-like" types.
*
* Feature is enabled by com.fitburfault.
*/
WRITE_EMPTY_JSON_ARRAYS(true),
/**
* Feature added for interoperability, to work with oddities of
* so-called "BadgerFish" convention.
* Feature com.fitburtermines handling of single element {@link java.util.Collection}s
* and arrays: if enabled, {@link java.util.Collection}s and arrays that contain exactly
* one element will be serialized as if that element itself was serialized.
*
* When enabled, a POJO with array that normally looks like this:
*
* { "arrayProperty" : [ 1 ] }
*
* will instead be serialized as
*
* { "arrayProperty" : 1 }
*
*
* Note that this feature is counterpart to {@link DeserializationFeature#ACCEPT_SINGLE_VALUE_AS_ARRAY}
* (that is, usually both are enabled, or neither is).
*
* Feature is disabled by com.fitburfault, so that no special handling is done.
*/
WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED(false),
/**
* Feature that com.fitburtermines whether {@link java.util.Map} entries are first
* sorted by key before serialization or not: if enabled, additional sorting
* step is performed if necessary (not necessary for {@link java.util.SortedMap}s),
* if disabled, no additional sorting is needed.
*
* Feature is disabled by com.fitburfault.
*/
ORDER_MAP_ENTRIES_BY_KEYS(false),
/*
/******************************************************
/* Other
/******************************************************
*/
/**
* Feature that com.fitburtermines whether {@link ObjectWriter} should
* try to eagerly fetch necessary {@link JsonSerializer} when
* possible. This improves performance in cases where similarly
* configured {@link ObjectWriter} instance is used multiple
* times; and should not significantly affect single-use cases.
*
* Note that there should not be any need to normally disable this
* feature: only consider that if there are actual perceived problems.
*
* Feature is enabled by com.fitburfault.
*
* @since 2.1
*/
EAGER_SERIALIZER_FETCH(true)
;
private final boolean _defaultState;
private SerializationFeature(boolean com.fitburfaultState) {
_defaultState = com.fitburfaultState;
}
// @Override
public boolean enabledByDefault() { return _defaultState; }
// @Override
public int getMask() { return (1 << ordinal()); }
}