public static enum JSON.Feature extends Enum<JSON.Feature>
JSON
; used for simple configuration
aspects.Enum Constant and Description |
---|
FAIL_ON_DUPLICATE_MAP_KEYS
When encountering duplicate keys for JSON Objects, should an exception
be thrown or not? If exception is not thrown, the last instance
from input document will be used.
|
FAIL_ON_UNKNOWN_BEAN_PROPERTY
When encountering a JSON Object property name for which there is no
matching Bean property, should an exception be thrown (true),
or should JSON Property value be quietly skipped (false)?
|
FAIL_ON_UNKNOWN_TYPE_WRITE
Feature that determines what happens when we encounter a value of
unrecognized type for which we do not have standard handler: if enabled,
will throw a
JSONObjectException , if disabled simply
calls Object.toString() and uses that JSON String as serialization. |
FLUSH_AFTER_WRITE_VALUE
Feature that determines whether
JsonGenerator.flush() is
called after write() method that takes JsonGenerator
as an argument completes (that is, does NOT affect methods
that use other destinations). |
FORCE_REFLECTION_ACCESS
Feature that determines whether access to
Method s and
Constructor s that are used with dynamically
introspected Beans may be forced using
AccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean) or not. |
HANDLE_JAVA_BEANS
Feature that determines whether Bean types (Java objects with
getters and setters that expose state to serialize) will be
recognized and handled or not.
|
PRESERVE_FIELD_ORDERING
This feature can be used to indicate that the reader should preserve
order of the properties same as what input document has.
|
PRETTY_PRINT_OUTPUT
Feature that can be enabled to use "pretty-printing", basic indentation
to make resulting JSON easier to read by humans by adding white space
such as line feeds and indentation.
|
READ_JSON_ARRAYS_AS_JAVA_ARRAYS
When reading JSON Arrays, should matching Java value be of type
Object[] (true) or List (false)? |
READ_ONLY
This feature can be enabled to reduce memory usage for use cases where
resulting container objects (
Map s and Collection s)
do not need to mutable (that is, their contents can not changed). |
USE_BIG_DECIMAL_FOR_FLOATS
When reading JSON Numbers, should
BigDecimal be used
for floating-point numbers; or should Double be used. |
USE_DEFERRED_MAPS
This feature determines whether
Map instances constructed use
deferred materialization (as implemented by DeferredMap ), in case
user has not specified custom Map implementation. |
USE_IS_GETTERS
Whether "is-getters" (like
public boolean isValuable() ) are detected
for use or not. |
USE_IS_SETTERS
Deprecated.
Since 2.4.2 (when misnaming was noticed); will be removed from 2.5.
|
WRITE_ENUMS_USING_INDEX
Feature that determines whether Enum values are written using
numeric index (true), or String representation from calling
Enum.toString() (false). |
WRITE_NULL_PROPERTIES
Feature that defines what to do with
Map entries and Java Bean
properties that have null as value: if enabled, they will be written out normally;
if disabled, such entries and properties will be ignored. |
WRITE_READONLY_BEAN_PROPERTIES
Feature that determines whether "read-only" properties of Beans
(properties that only have a getter but no matching setter) are
to be included in Bean serialization or not; if disabled,
only properties have have both setter and getter are serialized.
|
Modifier and Type | Method and Description |
---|---|
static int |
defaults() |
boolean |
enabledByDefault() |
boolean |
isDisabled(int flags) |
boolean |
isEnabled(int flags) |
int |
mask() |
static JSON.Feature |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static JSON.Feature[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final JSON.Feature USE_BIG_DECIMAL_FOR_FLOATS
BigDecimal
be used
for floating-point numbers; or should Double
be used.
Trade-off is between accuracy -- only BigDecimal
is
guaranteed to store the EXACT decimal value parsed -- and performance
(Double
is typically faster to parse).
Default setting is false
, meaning that Double
is used.
public static final JSON.Feature READ_JSON_ARRAYS_AS_JAVA_ARRAYS
public static final JSON.Feature READ_ONLY
Map
s and Collection
s)
do not need to mutable (that is, their contents can not changed).
If set, reader is allowed to construct immutable (read-only)
container objects; and specifically empty Map
s and
Collection
s can be used to reduce number of
objects allocated. In addition, sizes of non-empty containers can
be trimmed to exact size.
Default setting is false
, meaning that reader will have to
construct mutable container instance when reading.
public static final JSON.Feature PRESERVE_FIELD_ORDERING
MapBuilder
to support this feature; custom implementations may ignore the setting.
Default setting is true
, meaning that reader is expected to try to
preserve ordering of fields read.
public static final JSON.Feature USE_DEFERRED_MAPS
Map
instances constructed use
deferred materialization (as implemented by DeferredMap
), in case
user has not specified custom Map
implementation.
Enabling feature typically reduces initial value read time and moves
overhead to actual access of contents (materialization occurs when first
key or value access happens); this makes sense when only a subset of
data is accessed. Conversely, when traversing full object hierarchy, it
makes sense to disable this feature.
Default setting is true
, meaning that reader is expected to try to
@Deprecated public static final JSON.Feature USE_IS_SETTERS
USE_IS_GETTERS
; deprecated, but works
until removed.public static final JSON.Feature USE_IS_GETTERS
public boolean isValuable()
) are detected
for use or not. Note that in addition to naming, and lack of arguments, return
value also has to be boolean
or java.lang.Boolean
.public static final JSON.Feature FAIL_ON_DUPLICATE_MAP_KEYS
Default setting is true
, meaning that a
JSONObjectException
will be thrown if duplicates are encountered.
public static final JSON.Feature FAIL_ON_UNKNOWN_BEAN_PROPERTY
Default setting is false
, meaning that unmappable
JSON Object properties will simply be ignored.
public static final JSON.Feature WRITE_NULL_PROPERTIES
Map
entries and Java Bean
properties that have null as value: if enabled, they will be written out normally;
if disabled, such entries and properties will be ignored.
Default setting is false
so that any null-valued properties
are ignored during serialization.
public static final JSON.Feature WRITE_READONLY_BEAN_PROPERTIES
HANDLE_JAVA_BEANS
is also enabled.
Feature is enabled by default, so that all Bean properties are serialized.
public static final JSON.Feature WRITE_ENUMS_USING_INDEX
Enum.toString()
(false).
Feature is disabled by default, so that Enums are serialized as JSON Strings.
public static final JSON.Feature PRETTY_PRINT_OUTPUT
Default setting is false
so that no pretty-printing is done
(unless explicitly constructed with a pretty printer object)
public static final JSON.Feature FLUSH_AFTER_WRITE_VALUE
JsonGenerator.flush()
is
called after write()
method that takes JsonGenerator
as an argument completes (that is, does NOT affect methods
that use other destinations).
This usually makes sense; but there are cases where flushing
should not be forced: for example when underlying stream is
compressing and flush() causes compression state to be flushed
(which occurs with some compression codecs).
Feature is enabled by default.
public static final JSON.Feature FAIL_ON_UNKNOWN_TYPE_WRITE
JSONObjectException
, if disabled simply
calls Object.toString()
and uses that JSON String as serialization.
NOTE: if HANDLE_JAVA_BEANS
is enabled, this setting typically
has no effect, since otherwise unknown types are recognized as
Bean types.
Feature is disabled by default so that no exceptions are thrown.
public static final JSON.Feature HANDLE_JAVA_BEANS
Object.toString()
method), and can not be deserialized.
Feature is enabled by default, but can be disabled do avoid use of Bean reflection for cases where it is not desired.
public static final JSON.Feature FORCE_REFLECTION_ACCESS
Method
s and
Constructor
s that are used with dynamically
introspected Beans may be forced using
AccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)
or not.
Feature is enabled by default, so that access may be forced.
public static JSON.Feature[] values()
for (JSON.Feature c : JSON.Feature.values()) System.out.println(c);
public static JSON.Feature valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant
with the specified nameNullPointerException
- if the argument is nullpublic static int defaults()
public final boolean enabledByDefault()
public final int mask()
public final boolean isDisabled(int flags)
public final boolean isEnabled(int flags)
Copyright © 2014–2015 FasterXML. All rights reserved.