Enum JSONReader.Feature
- All Implemented Interfaces:
Serializable,Comparable<JSONReader.Feature>,java.lang.constant.Constable
- Enclosing class:
JSONReader
Features can be enabled in several ways:
- Using factory methods like
JSONReader.of(String, Context)withJSONFactory.createReadContext(JSONReader.Feature...) - Using
JSONReader.Context.config(Feature...)method - Using
JSONFactory.getDefaultReaderFeatures()for global configuration
Example usage:
// Enable FieldBased feature for this reader only
try (JSONReader reader = JSONReader.of(json, JSONReader.Feature.FieldBased)) {
MyObject obj = reader.read(MyObject.class);
}
// Enable multiple features
try (JSONReader reader = JSONReader.of(json,
JSONReader.Feature.FieldBased,
JSONReader.Feature.TrimString)) {
MyObject obj = reader.read(MyObject.class);
}
// Using context configuration
JSONReader.Context context = new JSONReader.Context();
context.config(JSONReader.Feature.FieldBased);
try (JSONReader reader = JSONReader.of(json, context)) {
MyObject obj = reader.read(MyObject.class);
}
Features are implemented as bitmask flags for efficient storage and checking. Each feature has a unique mask value that is used internally to determine whether the feature is enabled in a given configuration.
- Since:
- 2.0.0
- See Also:
-
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 whether to allow unquoted field names in JSON.Feature that determines whether to treat Base64-encoded strings as byte arrays during deserialization.Feature that disables reference detection during deserialization.Feature that disables the support for single quote.Feature that determines whether to unwrap single-element string arrays to scalar values.Feature that determines how to handle duplicate keys in JSON objects.Feature that determines whether to convert empty strings to null values during deserialization.Feature that determines whether to throw an exception when an enum value in JSON does not match any of the defined enum constants.Feature that determines whether to throw an exception when encountering non-serializable classes during deserialization.Feature that determines whether to throw an exception when autoType is not supported.Feature that determines whether to throw an exception when null values are encountered for primitive types during deserialization.Feature that determines whether to throw an exception when unknown properties are encountered during deserialization.Feature that determines whether to use field-based deserialization instead of getter/setter-based deserialization.Feature that determines whether to ignore autoType mismatches during deserialization.Feature that determines whether to ignore checking for resource cleanup.Feature that determines whether to ignore non-serializable classes during deserialization.Feature that determines whether to ignore null property values during deserialization.Feature that determines whether to ignore null values when setting properties.Feature that determines whether to initialize string fields as empty strings instead of null values.Feature that determines whether to avoid throwing exceptions on number overflow during deserialization.Feature that determines whether to treat non-string keys as strings during deserialization.Feature that determines whether to cast non-zero numbers to boolean true during deserialization.Feature that determines whether to return null on error during deserialization.Feature that determines whether to support deserializing JSON arrays into Java beans.Deprecated.It is not safe to explicitly turn on autoType, it is recommended to use AutoTypeBeforeHandlerFeature that enables support for Class.forName() during deserialization.Feature that enables smart matching of field names during deserialization.Feature that determines whether to trim whitespace from string values during deserialization.Feature that determines whether to deserialize floating-point numbers as BigDecimal when the target type is double.Feature that determines whether to deserialize floating-point numbers as BigDecimal when the target type is float.Feature that determines whether JSON integral (non-floating-point) numbers are to be deserialized intoBigIntegers if only generic type description (eitherObjectorNumber, or within untypedMaporCollectioncontext) is available.Feature that determines whether to use default constructors as much as possible during deserialization.Feature that determines whether to deserialize decimal numbers as double values.Feature that determines how "small" JSON integral (non-floating-point) numbers -- ones that fit in 32-bit signed integer (`int`) -- are bound when target type is loosely typed asObjectorNumber(or within untypedMaporCollectioncontext).Feature that determines whether to use native Java objects (HashMap, ArrayList) instead of FASTJSON's JSONObject and JSONArray during deserialization. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanisEnabled(long features) Checks if this feature is enabled in the specified features bitmask.static booleanisEnabled(long features, JSONReader.Feature feature) Checks if the specified feature is enabled in the given features bitmask.static longof(JSONReader.Feature[] features) Combines the masks of the specified features into a single bitmask.static JSONReader.FeatureReturns the enum constant of this type with the specified name.static JSONReader.Feature[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
FieldBased
Feature that determines whether to use field-based deserialization instead of getter/setter-based deserialization. When enabled, fields are directly accessed rather than using getter and setter methods. This can improve performance but may bypass validation logic in setters.By default, this feature is disabled, meaning that getter/setter-based deserialization is used.
- Since:
- 2.0.0
-
IgnoreNoneSerializable
Feature that determines whether to ignore non-serializable classes during deserialization. When enabled, classes that do not implementSerializablewill be ignored rather than causing an exception to be thrown.By default, this feature is disabled, meaning that non-serializable classes are not ignored.
- Since:
- 2.0.0
-
ErrorOnNoneSerializable
Feature that determines whether to throw an exception when encountering non-serializable classes during deserialization. When enabled, an exception will be thrown if a class does not implementSerializable.By default, this feature is disabled, meaning that no exception is thrown for non-serializable classes.
- Since:
- 2.0.14
-
SupportArrayToBean
Feature that determines whether to support deserializing JSON arrays into Java beans. When enabled, JSON arrays can be mapped to Java bean properties, with each array element corresponding to a property in the bean.By default, this feature is disabled, meaning that array-to-bean conversion is not supported.
- Since:
- 2.0.0
-
InitStringFieldAsEmpty
Feature that determines whether to initialize string fields as empty strings instead of null values. When enabled, string fields will be initialized with empty strings ("") rather than null.By default, this feature is disabled, meaning that string fields are initialized with null values.
- Since:
- 2.0.0
-
SupportAutoType
Deprecated.It is not safe to explicitly turn on autoType, it is recommended to use AutoTypeBeforeHandlerFeature that enables automatic type detection during deserialization. It is not safe to explicitly turn on autoType, it is recommended to use AutoTypeBeforeHandler.This feature is deprecated and should not be used in production code.
- Since:
- 2.0.0
-
SupportSmartMatch
Feature that enables smart matching of field names during deserialization. When enabled, field names in JSON can be matched to Java bean properties in a case-insensitive manner or with other smart matching rules.By default, this feature is disabled, meaning that exact field name matching is required.
- Since:
- 2.0.0
-
UseNativeObject
Feature that determines whether to use native Java objects (HashMap, ArrayList) instead of FASTJSON's JSONObject and JSONArray during deserialization. When enabled, standard Java collections are used rather than FASTJSON-specific ones.By default, this feature is disabled, meaning that FASTJSON's JSONObject and JSONArray are used.
- Since:
- 2.0.0
-
SupportClassForName
Feature that enables support for Class.forName() during deserialization. When enabled, the deserializer can use Class.forName() to load classes by name.By default, this feature is disabled.
- Since:
- 2.0.0
-
IgnoreSetNullValue
Feature that determines whether to ignore null values when setting properties. When enabled, null values in JSON will not be set on Java bean properties, preserving their default values.By default, this feature is disabled, meaning that null values are set on properties.
- Since:
- 2.0.0
-
UseDefaultConstructorAsPossible
Feature that determines whether to use default constructors as much as possible during deserialization. When enabled, the deserializer will prefer to use default (no-argument) constructors when creating objects.By default, this feature is disabled.
- Since:
- 2.0.0
-
UseBigDecimalForFloats
Feature that determines whether to deserialize floating-point numbers as BigDecimal when the target type is float. When enabled, float values will be represented with higher precision using BigDecimal.By default, this feature is disabled, meaning that standard float precision is used.
- Since:
- 2.0.0
-
UseBigDecimalForDoubles
Feature that determines whether to deserialize floating-point numbers as BigDecimal when the target type is double. When enabled, double values will be represented with higher precision using BigDecimal.By default, this feature is disabled, meaning that standard double precision is used.
- Since:
- 2.0.0
-
ErrorOnEnumNotMatch
Feature that determines whether to throw an exception when an enum value in JSON does not match any of the defined enum constants. When enabled, an exception will be thrown if an unknown enum value is encountered.By default, this feature is disabled, meaning that unknown enum values are ignored.
- Since:
- 2.0.0
-
TrimString
Feature that determines whether to trim whitespace from string values during deserialization. When enabled, leading and trailing whitespace will be removed from string values.By default, this feature is disabled, meaning that string values are not trimmed.
- Since:
- 2.0.0
-
ErrorOnNotSupportAutoType
Feature that determines whether to throw an exception when autoType is not supported. When enabled, an exception will be thrown if autoType functionality is not available.By default, this feature is disabled.
- Since:
- 2.0.0
-
DuplicateKeyValueAsArray
Feature that determines how to handle duplicate keys in JSON objects. When enabled, duplicate keys will be stored as arrays rather than overwriting previous values.By default, this feature is disabled, meaning that duplicate keys overwrite previous values.
- Since:
- 2.0.0
-
AllowUnQuotedFieldNames
Feature that determines whether to allow unquoted field names in JSON. When enabled, field names in JSON objects do not need to be enclosed in quotes.By default, this feature is disabled, meaning that field names must be quoted.
- Since:
- 2.0.0
-
NonStringKeyAsString
Feature that determines whether to treat non-string keys as strings during deserialization. When enabled, keys in JSON objects that are not strings will be converted to string representation.By default, this feature is disabled.
- Since:
- 2.0.0
-
Base64StringAsByteArray
Feature that determines whether to treat Base64-encoded strings as byte arrays during deserialization. When enabled, strings that contain Base64-encoded data will be automatically decoded to byte arrays.By default, this feature is disabled.
- Since:
- 2.0.13
-
IgnoreCheckClose
Feature that determines whether to ignore checking for resource cleanup. When enabled, the deserializer will not perform checks to ensure proper resource cleanup.By default, this feature is disabled.
- Since:
- 2.0.16
-
ErrorOnNullForPrimitives
Feature that determines whether to throw an exception when null values are encountered for primitive types during deserialization. When enabled, an exception will be thrown if a null value is found for a primitive type field.By default, this feature is disabled, meaning that primitive types are initialized with default values.
- Since:
- 2.0.20
-
NullOnError
Feature that determines whether to return null on error during deserialization. When enabled, errors during deserialization will result in null values rather than exceptions.By default, this feature is disabled.
- Since:
- 2.0.20
-
IgnoreAutoTypeNotMatch
Feature that determines whether to ignore autoType mismatches during deserialization. When enabled, mismatches between expected and actual types in autoType scenarios will be ignored.By default, this feature is disabled.
- Since:
- 2.0.21
-
NonZeroNumberCastToBooleanAsTrue
Feature that determines whether to cast non-zero numbers to boolean true during deserialization. When enabled, any non-zero numeric value will be treated as true when converting to boolean.By default, this feature is disabled.
- Since:
- 2.0.24
-
IgnoreNullPropertyValue
Feature that determines whether to ignore null property values during deserialization. When enabled, properties with null values in JSON will be ignored rather than set to null.By default, this feature is disabled.
- Since:
- 2.0.40
-
ErrorOnUnknownProperties
Feature that determines whether to throw an exception when unknown properties are encountered during deserialization. When enabled, an exception will be thrown if JSON contains properties that do not exist in the target class.By default, this feature is disabled, meaning that unknown properties are ignored.
- Since:
- 2.0.42
-
EmptyStringAsNull
Feature that determines whether to convert empty strings to null values during deserialization. When enabled, empty string values ("") in JSON will be converted to null values.By default, this feature is disabled, meaning that empty strings are preserved as empty strings.
- Since:
- 2.0.48
-
NonErrorOnNumberOverflow
Feature that determines whether to avoid throwing exceptions on number overflow during deserialization. When enabled, numeric overflow conditions will not cause exceptions to be thrown.By default, this feature is disabled, meaning that number overflow will cause exceptions.
- Since:
- 2.0.48
-
UseBigIntegerForInts
Feature that determines whether JSON integral (non-floating-point) numbers are to be deserialized intoBigIntegers if only generic type description (eitherObjectorNumber, or within untypedMaporCollectioncontext) is available. If enabled such values will be deserialized asBigIntegers; if disabled, will be deserialized as "smallest" available type, which is eitherInteger,LongorBigInteger, depending on number of digits.Feature is disabled by default, meaning that "untyped" integral numbers will by default be deserialized using whatever is the most compact integral type, to optimize efficiency.
- Since:
- 2.0.51
-
UseLongForInts
Feature that determines how "small" JSON integral (non-floating-point) numbers -- ones that fit in 32-bit signed integer (`int`) -- are bound when target type is loosely typed asObjectorNumber(or within untypedMaporCollectioncontext). If enabled, such values will be deserialized asLong; if disabled, they will be deserialized as "smallest" available type,Integer.Note: if
UseBigIntegerForIntsis enabled, it has precedence over this setting, forcing use ofBigIntegerfor all integral values.Feature is disabled by default, meaning that "untyped" integral numbers will by default be deserialized using
Integerif value fits.- Since:
- 2.0.51
-
DisableSingleQuote
Feature that disables the support for single quote. When enabled, single quotes are not allowed as string delimiters in JSON.By default, this feature is disabled, meaning that single quotes are supported.
- Since:
- 2.0.53
-
UseDoubleForDecimals
Feature that determines whether to deserialize decimal numbers as double values. When enabled, decimal values will be represented as double precision floating-point numbers.By default, this feature is disabled.
- Since:
- 2.0.53
-
DisableReferenceDetect
Feature that disables reference detection during deserialization. When enabled, JSON references (such as those using $ref) will not be processed.By default, this feature is disabled, meaning that reference detection is enabled.
- Since:
- 2.0.56
-
DisableStringArrayUnwrapping
Feature that determines whether to unwrap single-element string arrays to scalar values. When enabled, JSON arrays containing a single string element will be unwrapped to just that string value rather than returning the array. For example, ["value"] would be returned as "value".- Since:
- 2.0.60
-
-
Field Details
-
mask
public final long mask
-
-
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
-
of
Combines the masks of the specified features into a single bitmask.- Parameters:
features- The features to combine- Returns:
- A bitmask representing the combined features, or 0 if features is null
-
isEnabled
public boolean isEnabled(long features) Checks if this feature is enabled in the specified features bitmask.- Parameters:
features- The features bitmask to check- Returns:
- true if this feature is enabled, false otherwise
-
isEnabled
Checks if the specified feature is enabled in the given features bitmask.- Parameters:
features- The features bitmask to checkfeature- The feature to check for- Returns:
- true if the specified feature is enabled, false otherwise
-