Class JsonConfig

java.lang.Object
cloud.opencode.base.json.JsonConfig

public final class JsonConfig extends Object
JSON Config - Configuration for JSON Processing JSON 配置 - JSON 处理的配置

This class provides configuration options for JSON serialization and deserialization, including features, naming strategies, and limits.

此类提供 JSON 序列化和反序列化的配置选项, 包括特性、命名策略和限制。

Example | 示例:

JsonConfig config = JsonConfig.builder()
    .enable(JsonFeature.PRETTY_PRINT)
    .enable(JsonFeature.IGNORE_UNKNOWN_PROPERTIES)
    .namingStrategy(JsonNaming.Strategy.SNAKE_CASE)
    .dateFormat("yyyy-MM-dd HH:mm:ss")
    .timezone(ZoneId.of("Asia/Shanghai"))
    .maxDepth(100)
    .build();

OpenJson json = OpenJson.withConfig(config);

Features | 主要功能:

  • Builder pattern for flexible configuration - 构建器模式实现灵活配置
  • Feature toggle for serialization/deserialization - 序列化/反序列化特性开关
  • Configurable naming strategies, date formats, and limits - 可配置的命名策略、日期格式和限制

Security | 安全性:

  • Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
  • Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
Since:
JDK 25, opencode-base-json V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Field Details

    • DEFAULT

      public static final JsonConfig DEFAULT
      Default configuration 默认配置
  • Method Details

    • builder

      public static JsonConfig.Builder builder()
      Creates a new builder. 创建新的构建器。
      Returns:
      a new builder - 新构建器
    • toBuilder

      public JsonConfig.Builder toBuilder()
      Creates a builder initialized with this config. 创建使用此配置初始化的构建器。
      Returns:
      a new builder - 新构建器
    • isEnabled

      public boolean isEnabled(JsonFeature feature)
      Returns whether a feature is enabled. 返回特性是否启用。
      Parameters:
      feature - the feature to check - 要检查的特性
      Returns:
      true if enabled - 如果启用则返回 true
    • getEnabledFeatures

      public Set<JsonFeature> getEnabledFeatures()
      Returns the enabled features. 返回启用的特性。
      Returns:
      the enabled features - 启用的特性
    • getNamingStrategy

      public JsonNaming.Strategy getNamingStrategy()
      Returns the naming strategy. 返回命名策略。
      Returns:
      the naming strategy - 命名策略
    • getDateFormat

      public String getDateFormat()
      Returns the date format pattern. 返回日期格式模式。
      Returns:
      the date format - 日期格式
    • getTimezone

      public ZoneId getTimezone()
      Returns the timezone. 返回时区。
      Returns:
      the timezone - 时区
    • getMaxDepth

      public int getMaxDepth()
      Returns the maximum nesting depth. 返回最大嵌套深度。
      Returns:
      the max depth - 最大深度
    • getMaxStringLength

      public int getMaxStringLength()
      Returns the maximum string length. 返回最大字符串长度。
      Returns:
      the max string length - 最大字符串长度
    • getMaxSize

      public int getMaxSize()
      Returns the maximum array/object size. 返回最大数组/对象大小。
      Returns:
      the max size - 最大大小
    • getIndent

      public String getIndent()
      Returns the indentation string. 返回缩进字符串。
      Returns:
      the indent - 缩进