Enum Class JsonFeature
- All Implemented Interfaces:
Serializable, Comparable<JsonFeature>, Constable
JSON Feature - Configuration Features for JSON Processing
JSON 特性 - JSON 处理的配置特性
This enum defines configurable features that control JSON serialization and deserialization behavior.
此枚举定义控制 JSON 序列化和反序列化行为的可配置特性。
Example | 示例:
JsonConfig config = JsonConfig.builder()
.enable(JsonFeature.PRETTY_PRINT)
.enable(JsonFeature.IGNORE_UNKNOWN_PROPERTIES)
.build();
Features | 主要功能:
- Categorized features: serialization, deserialization, security - 分类特性:序列化、反序列化、安全
- Default enabled/disabled state per feature - 每个特性的默认启用/禁用状态
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: N/A - 空值安全: 不适用
- Since:
- JDK 25, opencode-base-json V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumFeature category enumeration 特性类别枚举Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionAccept empty string as null for object types.Accept single values as arrays.Allow comments in JSON (non-standard).Allow single quotes instead of double quotes (non-standard).Allow trailing comma in arrays and objects (non-standard).Allow unquoted field names (non-standard).Escape non-ASCII characters.Fail on null for primitives.Fail on numbers for enums.Ignore unknown properties during deserialization.Include empty collections in output.Include null properties in output.Limit maximum number of entries in arrays/objects.Limit maximum nesting depth to prevent stack overflow.Limit maximum string length to prevent DoS attacks.Enable pretty printing with indentation.Read date timestamps with nanosecond precision.Read unknown enum values as null instead of throwing.Use @JsonEnumDefaultValue for unknown enum values.Sort map keys alphabetically.Unwrap root element wrapping during deserialization.Use BigDecimal for floating-point numbers.Use BigInteger for large integers.Wrap output with root element name.Write date timestamps with nanosecond precision.Write dates as ISO-8601 strings instead of timestamps.Write empty arrays for null array values.Write enums as ordinal index instead of name.Write enums using their name() instead of toString().Write null values for map entries. -
Method Summary
Modifier and TypeMethodDescriptionReturns the feature category.booleanReturns whether this feature is a deserialization feature.booleanReturns whether this feature is enabled by default.booleanReturns whether this feature is a security feature.booleanReturns whether this feature is a serialization feature.static JsonFeatureReturns the enum constant of this class with the specified name.static JsonFeature[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
PRETTY_PRINT
Enable pretty printing with indentation. 启用带缩进的美化打印。Default: false
-
WRITE_DATES_AS_ISO8601
Write dates as ISO-8601 strings instead of timestamps. 将日期写为 ISO-8601 字符串而非时间戳。Default: true
-
WRITE_ENUMS_USING_NAME
Write enums using their name() instead of toString(). 使用枚举的 name() 而非 toString() 写入。Default: true
-
WRITE_NULL_MAP_VALUES
Write null values for map entries. 写入 Map 中的 null 值条目。Default: true
-
WRITE_EMPTY_ARRAYS_FOR_NULL
Write empty arrays for null array values. 为 null 数组值写入空数组。Default: false
-
SORT_MAP_KEYS
Sort map keys alphabetically. 按字母顺序排序 Map 键。Default: false
-
ESCAPE_NON_ASCII
Escape non-ASCII characters. 转义非 ASCII 字符。Default: false
-
INCLUDE_NULL_PROPERTIES
Include null properties in output. 在输出中包含 null 属性。Default: true
-
INCLUDE_EMPTY_COLLECTIONS
Include empty collections in output. 在输出中包含空集合。Default: true
-
WRAP_ROOT_VALUE
Wrap output with root element name. 使用根元素名称包裹输出。Default: false
-
WRITE_ENUMS_USING_INDEX
Write enums as ordinal index instead of name. 将枚举写为序号索引而非名称。Default: false
-
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS
Write date timestamps with nanosecond precision. 以纳秒精度写入日期时间戳。Default: false
-
IGNORE_UNKNOWN_PROPERTIES
Ignore unknown properties during deserialization. 反序列化时忽略未知属性。Default: true
-
ACCEPT_SINGLE_VALUE_AS_ARRAY
Accept single values as arrays. 接受单个值作为数组。Default: false
-
ACCEPT_EMPTY_STRING_AS_NULL
Accept empty string as null for object types. 对对象类型接受空字符串作为 null。Default: false
-
FAIL_ON_NULL_FOR_PRIMITIVES
Fail on null for primitives. 基本类型遇到 null 时失败。Default: false
-
FAIL_ON_NUMBERS_FOR_ENUMS
Fail on numbers for enums. 枚举遇到数字时失败。Default: false
-
USE_BIG_DECIMAL_FOR_FLOATS
Use BigDecimal for floating-point numbers. 对浮点数使用 BigDecimal。Default: false
-
USE_BIG_INTEGER_FOR_INTS
Use BigInteger for large integers. 对大整数使用 BigInteger。Default: false
-
ALLOW_COMMENTS
Allow comments in JSON (non-standard). 允许 JSON 中的注释(非标准)。Default: false
-
ALLOW_TRAILING_COMMA
Allow trailing comma in arrays and objects (non-standard). 允许数组和对象中的尾随逗号(非标准)。Default: false
-
ALLOW_UNQUOTED_FIELD_NAMES
Allow unquoted field names (non-standard). 允许不带引号的字段名(非标准)。Default: false
-
ALLOW_SINGLE_QUOTES
Allow single quotes instead of double quotes (non-standard). 允许单引号代替双引号(非标准)。Default: false
-
READ_UNKNOWN_ENUM_VALUES_AS_NULL
Read unknown enum values as null instead of throwing. 将未知枚举值读为 null 而非抛出异常。Default: false
-
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE
Use @JsonEnumDefaultValue for unknown enum values. 对未知枚举值使用 @JsonEnumDefaultValue。Default: false
-
UNWRAP_ROOT_VALUE
Unwrap root element wrapping during deserialization. 反序列化时解包根元素包裹。Default: false
-
READ_DATE_TIMESTAMPS_AS_NANOSECONDS
Read date timestamps with nanosecond precision. 以纳秒精度读取日期时间戳。Default: false
-
LIMIT_STRING_LENGTH
Limit maximum string length to prevent DoS attacks. 限制最大字符串长度以防止 DoS 攻击。Default: true
-
LIMIT_NESTING_DEPTH
Limit maximum nesting depth to prevent stack overflow. 限制最大嵌套深度以防止栈溢出。Default: true
-
LIMIT_ENTRY_COUNT
Limit maximum number of entries in arrays/objects. 限制数组/对象中的最大条目数。Default: true
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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 class has no constant with the specified nameNullPointerException- if the argument is null
-
getCategory
Returns the feature category. 返回特性类别。- Returns:
- the category - 类别
-
isEnabledByDefault
public boolean isEnabledByDefault()Returns whether this feature is enabled by default. 返回此特性是否默认启用。- Returns:
- true if enabled by default - 如果默认启用则返回 true
-
isSerializationFeature
public boolean isSerializationFeature()Returns whether this feature is a serialization feature. 返回此特性是否为序列化特性。- Returns:
- true if serialization feature - 如果是序列化特性则返回 true
-
isDeserializationFeature
public boolean isDeserializationFeature()Returns whether this feature is a deserialization feature. 返回此特性是否为反序列化特性。- Returns:
- true if deserialization feature - 如果是反序列化特性则返回 true
-
isSecurityFeature
public boolean isSecurityFeature()Returns whether this feature is a security feature. 返回此特性是否为安全特性。- Returns:
- true if security feature - 如果是安全特性则返回 true
-