public static enum JSONReader.Feature extends java.lang.Enum<JSONReader.Feature>
Features can be enabled in several ways:
JSONReader.of(String, Context) with JSONFactory.createReadContext(JSONReader.Feature...)Context#config(Feature...) methodJSONFactory.getDefaultReaderFeatures() for global configurationExample 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.
JSONReader.Context,
JSONFactory| Enum Constant and Description |
|---|
AllowUnQuotedFieldNames
Feature that determines whether to allow unquoted field names in JSON.
|
Base64StringAsByteArray
Feature that determines whether to treat Base64-encoded strings as byte arrays during deserialization.
|
DisableReferenceDetect
Feature that disables reference detection during deserialization.
|
DisableSingleQuote
Feature that disables the support for single quote.
|
DisableStringArrayUnwrapping
Feature that disables unwrapping of single-element string arrays to scalar values.
|
DuplicateKeyValueAsArray
Feature that determines how to handle duplicate keys in JSON objects.
|
EmptyStringAsNull
Feature that determines whether to convert empty strings to null values during deserialization.
|
ErrorOnEnumNotMatch
Feature that determines whether to throw an exception when an enum value in JSON does not
match any of the defined enum constants.
|
ErrorOnNoneSerializable
Feature that determines whether to throw an exception when encountering non-serializable classes
during deserialization.
|
ErrorOnNotSupportAutoType
Feature that determines whether to throw an exception when autoType is not supported.
|
ErrorOnNullForPrimitives
Feature that determines whether to throw an exception when null values are encountered
for primitive types during deserialization.
|
ErrorOnUnknownProperties
Feature that determines whether to throw an exception when unknown properties are encountered
during deserialization.
|
FieldBased
Feature that determines whether to use field-based deserialization instead of getter/setter-based deserialization.
|
IgnoreAutoTypeNotMatch
Feature that determines whether to ignore autoType mismatches during deserialization.
|
IgnoreCheckClose
Feature that determines whether to ignore checking for resource cleanup.
|
IgnoreNoneSerializable
Feature that determines whether to ignore non-serializable classes during deserialization.
|
IgnoreNullPropertyValue
Feature that determines whether to ignore null property values during deserialization.
|
IgnoreSetNullValue
Feature that determines whether to ignore null values when setting properties.
|
InitStringFieldAsEmpty
Feature that determines whether to initialize string fields as empty strings instead of null values.
|
NonErrorOnNumberOverflow
Feature that determines whether to avoid throwing exceptions on number overflow during deserialization.
|
NonStringKeyAsString
Feature that determines whether to treat non-string keys as strings during deserialization.
|
NonZeroNumberCastToBooleanAsTrue
Feature that determines whether to cast non-zero numbers to boolean true during deserialization.
|
NullOnError
Feature that determines whether to return null on error during deserialization.
|
SupportArrayToBean
Feature that determines whether to support deserializing JSON arrays into Java beans.
|
SupportAutoType
Deprecated.
It is not safe to explicitly turn on autoType, it is recommended to use AutoTypeBeforeHandler
|
SupportClassForName
Feature that enables support for Class.forName() during deserialization.
|
SupportSmartMatch
Feature that enables smart matching of field names during deserialization.
|
TrimString
Feature that determines whether to trim whitespace from string values during deserialization.
|
UseBigDecimalForDoubles
Feature that determines whether to deserialize floating-point numbers as BigDecimal
when the target type is double.
|
UseBigDecimalForFloats
Feature that determines whether to deserialize floating-point numbers as BigDecimal
when the target type is float.
|
UseBigIntegerForInts
Feature that determines whether JSON integral (non-floating-point)
numbers are to be deserialized into
BigIntegers
if only generic type description (either Object or
Number, or within untyped Map
or Collection context) is available. |
UseDefaultConstructorAsPossible
Feature that determines whether to use default constructors as much as possible during deserialization.
|
UseDoubleForDecimals
Feature that determines whether to deserialize decimal numbers as double values.
|
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 as
Object or Number
(or within untyped Map or Collection context). |
UseNativeObject
Feature that determines whether to use native Java objects (HashMap, ArrayList) instead of
FASTJSON's JSONObject and JSONArray during deserialization.
|
| Modifier and Type | Field and Description |
|---|---|
long |
mask |
| Modifier and Type | Method and Description |
|---|---|
boolean |
isEnabled(long features)
Checks if this feature is enabled in the specified features bitmask.
|
static boolean |
isEnabled(long features,
JSONReader.Feature feature)
Checks if the specified feature is enabled in the given features bitmask.
|
static long |
of(JSONReader.Feature[] features)
Combines the masks of the specified features into a single bitmask.
|
static JSONReader.Feature |
valueOf(java.lang.String name)
Returns 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.
|
public static final JSONReader.Feature FieldBased
By default, this feature is disabled, meaning that getter/setter-based deserialization is used.
public static final JSONReader.Feature IgnoreNoneSerializable
Serializable will be ignored
rather than causing an exception to be thrown.
By default, this feature is disabled, meaning that non-serializable classes are not ignored.
public static final JSONReader.Feature ErrorOnNoneSerializable
Serializable.
By default, this feature is disabled, meaning that no exception is thrown for non-serializable classes.
public static final JSONReader.Feature SupportArrayToBean
By default, this feature is disabled, meaning that array-to-bean conversion is not supported.
public static final JSONReader.Feature InitStringFieldAsEmpty
By default, this feature is disabled, meaning that string fields are initialized with null values.
@Deprecated public static final JSONReader.Feature SupportAutoType
This feature is deprecated and should not be used in production code.
public static final JSONReader.Feature SupportSmartMatch
By default, this feature is disabled, meaning that exact field name matching is required.
public static final JSONReader.Feature UseNativeObject
By default, this feature is disabled, meaning that FASTJSON's JSONObject and JSONArray are used.
public static final JSONReader.Feature SupportClassForName
By default, this feature is disabled.
public static final JSONReader.Feature IgnoreSetNullValue
By default, this feature is disabled, meaning that null values are set on properties.
public static final JSONReader.Feature UseDefaultConstructorAsPossible
By default, this feature is disabled.
public static final JSONReader.Feature UseBigDecimalForFloats
By default, this feature is disabled, meaning that standard float precision is used.
public static final JSONReader.Feature UseBigDecimalForDoubles
By default, this feature is disabled, meaning that standard double precision is used.
public static final JSONReader.Feature ErrorOnEnumNotMatch
By default, this feature is disabled, meaning that unknown enum values are ignored.
public static final JSONReader.Feature TrimString
By default, this feature is disabled, meaning that string values are not trimmed.
public static final JSONReader.Feature ErrorOnNotSupportAutoType
By default, this feature is disabled.
public static final JSONReader.Feature DuplicateKeyValueAsArray
By default, this feature is disabled, meaning that duplicate keys overwrite previous values.
public static final JSONReader.Feature AllowUnQuotedFieldNames
By default, this feature is disabled, meaning that field names must be quoted.
public static final JSONReader.Feature NonStringKeyAsString
By default, this feature is disabled.
public static final JSONReader.Feature Base64StringAsByteArray
By default, this feature is disabled.
public static final JSONReader.Feature IgnoreCheckClose
By default, this feature is disabled.
public static final JSONReader.Feature ErrorOnNullForPrimitives
By default, this feature is disabled, meaning that primitive types are initialized with default values.
public static final JSONReader.Feature NullOnError
By default, this feature is disabled.
public static final JSONReader.Feature IgnoreAutoTypeNotMatch
By default, this feature is disabled.
public static final JSONReader.Feature NonZeroNumberCastToBooleanAsTrue
By default, this feature is disabled.
public static final JSONReader.Feature IgnoreNullPropertyValue
By default, this feature is disabled.
public static final JSONReader.Feature ErrorOnUnknownProperties
By default, this feature is disabled, meaning that unknown properties are ignored.
public static final JSONReader.Feature EmptyStringAsNull
By default, this feature is disabled, meaning that empty strings are preserved as empty strings.
public static final JSONReader.Feature NonErrorOnNumberOverflow
By default, this feature is disabled, meaning that number overflow will cause exceptions.
public static final JSONReader.Feature UseBigIntegerForInts
BigIntegers
if only generic type description (either Object or
Number, or within untyped Map
or Collection context) is available.
If enabled such values will be deserialized as
BigIntegers;
if disabled, will be deserialized as "smallest" available type,
which is either Integer, Long or
BigInteger, 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.
public static final JSONReader.Feature UseLongForInts
Object or Number
(or within untyped Map or Collection context).
If enabled, such values will be deserialized as Long;
if disabled, they will be deserialized as "smallest" available type,
Integer.
Note: if UseBigIntegerForInts is enabled, it has precedence
over this setting, forcing use of BigInteger for all
integral values.
Feature is disabled by default, meaning that "untyped" integral
numbers will by default be deserialized using Integer
if value fits.
public static final JSONReader.Feature DisableSingleQuote
By default, this feature is disabled, meaning that single quotes are supported.
public static final JSONReader.Feature UseDoubleForDecimals
By default, this feature is disabled.
public static final JSONReader.Feature DisableReferenceDetect
By default, this feature is disabled, meaning that reference detection is enabled.
public static final JSONReader.Feature DisableStringArrayUnwrapping
public static JSONReader.Feature[] values()
for (JSONReader.Feature c : JSONReader.Feature.values()) System.out.println(c);
public static JSONReader.Feature valueOf(java.lang.String name)
name - the name of the enum constant to be returned.java.lang.IllegalArgumentException - if this enum type has no constant with the specified namejava.lang.NullPointerException - if the argument is nullpublic static long of(JSONReader.Feature[] features)
features - The features to combinepublic boolean isEnabled(long features)
features - The features bitmask to checkpublic static boolean isEnabled(long features,
JSONReader.Feature feature)
features - The features bitmask to checkfeature - The feature to check for