Enum JSON.Feature
- All Implemented Interfaces:
Serializable,Comparable<JSON.Feature>,java.lang.constant.Constable
- Enclosing class:
- JSON
JSON; used for simple
configuration aspects.-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionFeature that determines if Enum deserialization should be case sensitive or not.Feature that will allow for more forgiving deserialization of incoming JSON.When encountering duplicate keys for JSON Objects, should an exception be thrown or not?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)?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 aJSONObjectException, if disabled simply callsObject.toString()and uses that JSON String as serialization.Feature that determines whetherJsonGenerator.flush()is called afterwrite()method that takes JsonGenerator as an argument completes (that is, does NOT affect methods that use other destinations).Feature that determines whether access toMethods andConstructors that are used with dynamically introspected Beans may be forced usingAccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)or not.Feature that determines whether Bean types (Java objects with getters and setters that expose state to serialize) will be recognized and handled or not.Feature that enables serialization and deserialization of non-final static fields.This feature can be used to indicate that the reader should preserve order of the properties same as what input document has.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.When reading JSON Arrays, should matching Java value be of typeObject[](true) orList(false)?This feature can be enabled to reduce memory usage for use cases where resulting container objects (Maps andCollections) do not need to mutable (that is, their contents can not changed).When reading JSON Numbers, shouldBigDecimalbe used for floating-point numbers; or shouldDoublebe used.This feature determines whetherMapinstances constructed use deferred materialization (as implemented byDeferredMap), in case user has not specified customMapimplementation.Feature that provides serialization support for Groovy and Java 17 records, by allowing reading of "non-get-getters" in a class, (like for a field namedamountthe getter would beamount()).Feature that enables use of public fields instead of setters and getters, in cases where no setter/getter is available.Whether "is-getters" (likepublic boolean isValuable()) are detected for use or not.Feature that determines whether Date (and date/time) values (and Date-based things likeCalendars) are to be serialized as numeric timestamps (true), or using a textual representation (false)Feature that determines whether Enum values are written using numeric index (true), or String representation from callingEnum.toString()(false).Feature that defines what to do withMapentries 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.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.Feature that determines whether record fields are serialized in declaration order (enabled) or not (disabled). -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanstatic intMethod for calculating bitset of features that force flushing of POJO handler caches.static intdefaults()final booleanfinal booleanisDisabled(int flags) final booleanisEnabled(int flags) final intmask()static JSON.FeatureReturns 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.
-
Enum Constant Details
-
USE_BIG_DECIMAL_FOR_FLOATS
When reading JSON Numbers, shouldBigDecimalbe used for floating-point numbers; or shouldDoublebe used. Trade-off is between accuracy -- onlyBigDecimalis guaranteed to store the EXACT decimal value parsed -- and performance (Doubleis typically faster to parse).Default setting is
false, meaning thatDoubleis used. -
READ_JSON_ARRAYS_AS_JAVA_ARRAYS
-
READ_ONLY
This feature can be enabled to reduce memory usage for use cases where resulting container objects (Maps andCollections) 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 emptyMaps andCollections 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. -
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. Note that it is up toMapBuilderto 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. -
USE_DEFERRED_MAPS
This feature determines whetherMapinstances constructed use deferred materialization (as implemented byDeferredMap), in case user has not specified customMapimplementation. 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 -
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.Default setting is
true, meaning that aJSONObjectExceptionwill be thrown if duplicates are encountered. -
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)?Default setting is
false, meaning that unmappable JSON Object properties will simply be ignored. -
WRITE_NULL_PROPERTIES
Feature that defines what to do withMapentries 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
falseso that any null-valued properties are ignored during serialization. -
WRITE_ENUMS_USING_INDEX
Feature that determines whether Enum values are written using numeric index (true), or String representation from callingEnum.toString()(false).Feature is disabled by default, so that Enums are serialized as JSON Strings.
-
WRITE_DATES_AS_TIMESTAMP
Feature that determines whether Date (and date/time) values (and Date-based things likeCalendars) are to be serialized as numeric timestamps (true), or using a textual representation (false)Feature is disabled by default, so that date/time values are serialized as text, NOT timestamp.
- Since:
- 2.7
-
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.Default setting is
falseso that no pretty-printing is done (unless explicitly constructed with a pretty printer object) -
FLUSH_AFTER_WRITE_VALUE
Feature that determines whetherJsonGenerator.flush()is called afterwrite()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.
-
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 aJSONObjectException, if disabled simply callsObject.toString()and uses that JSON String as serialization.NOTE: if
HANDLE_JAVA_BEANSis 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.
-
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. When enabled, any types that are not recognized as standard JDK data structures, primitives or wrapper values will be introspected and handled as Java Beans (can be read/written as long as JSON matches properties discovered); when disabled, they may only be serialized (usingObject.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.
-
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. Note that feature is only used ifHANDLE_JAVA_BEANSis also enabled.Feature is enabled by default, so that all Bean properties are serialized.
-
WRITE_RECORD_FIELDS_IN_DECLARATION_ORDER
Feature that determines whether record fields are serialized in declaration order (enabled) or not (disabled). If disabled, record fields are serialized same way as POJO properties, that is, alphabetically sorted.Feature is disabled by default for backwards compatibility reasons.
- Since:
- 2.19
-
FORCE_REFLECTION_ACCESS
Feature that determines whether access toMethods andConstructors that are used with dynamically introspected Beans may be forced usingAccessibleObject.setAccessible(java.lang.reflect.AccessibleObject[], boolean)or not.Feature is enabled by default, so that access may be forced.
-
USE_IS_GETTERS
Whether "is-getters" (likepublic boolean isValuable()) are detected for use or not. Note that in addition to naming, and lack of arguments, return value also has to bebooleanorjava.lang.Boolean.- Since:
- 2.5
-
USE_FIELD_MATCHING_GETTERS
Feature that provides serialization support for Groovy and Java 17 records, by allowing reading of "non-get-getters" in a class, (like for a field namedamountthe getter would beamount()).Feature is disabled by default for backward compatibility.
- Since:
- 2.17
-
USE_FIELDS
Feature that enables use of public fields instead of setters and getters, in cases where no setter/getter is available.Feature is enabled by default since 2.10 (but was disabled for 2.8 and 2.9), so public fields are discovered by default.
- Since:
- 2.8 (enabled by default since 2.10)
-
INCLUDE_STATIC_FIELDS
Feature that enables serialization and deserialization of non-final static fields.Feature did not exist, but was implicitly enabled by default. disabled for 2.13).
- Since:
- 2.13
-
ACCEPT_CASE_INSENSITIVE_PROPERTIES
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 for names that are already lower-case should be negligible however.
Feature is disabled by default.
- Since:
- 2.13
-
ACCEPT_CASE_INSENSITIVE_ENUMS
Feature that determines if Enum deserialization should be case sensitive or not. If enabled, Enum deserialization will ignore case, that is, case of incoming String value and enum id (dependant on other settings, either `name()`, `toString()`, or explicit override) do not need to match.Feature is disabled by default.
- Since:
- 2.13
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
defaults
public static int defaults() -
cacheBreakers
public static int cacheBreakers()Method for calculating bitset of features that force flushing of POJO handler caches.- Since:
- 2.8
-
enabledByDefault
public final boolean enabledByDefault() -
affectsCaching
public final boolean affectsCaching() -
mask
public final int mask() -
isDisabled
public final boolean isDisabled(int flags) -
isEnabled
public final boolean isEnabled(int flags)
-