Class RecordMapper.Builder<S,T>

java.lang.Object
cloud.opencode.base.reflect.record.RecordMapper.Builder<S,T>
Type Parameters:
S - the source type | 源类型
T - the target type | 目标类型
Enclosing class:
RecordMapper<S,T>

public static final class RecordMapper.Builder<S,T> extends Object
Builder for RecordMapper RecordMapper构建器

Configures field mappings, exclusions, converters, and null handling.

配置字段映射、排除、转换器和空值处理。

Since:
JDK 25, opencode-base-reflect V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • map

      public RecordMapper.Builder<S,T> map(String sourceField, String targetField)
      Maps a source field name to a target field name 将源字段名映射到目标字段名
      Parameters:
      sourceField - the source field name | 源字段名
      targetField - the target field name | 目标字段名
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if sourceField or targetField is null | 如果字段名为null
    • exclude

      public RecordMapper.Builder<S,T> exclude(String fieldName)
      Excludes a field from mapping 从映射中排除字段
      Parameters:
      fieldName - the field name to exclude | 要排除的字段名
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if fieldName is null | 如果字段名为null
    • convert

      public RecordMapper.Builder<S,T> convert(String targetField, Function<Object,Object> converter)
      Adds a custom converter for a target field 为目标字段添加自定义转换器
      Parameters:
      targetField - the target field name | 目标字段名
      converter - the converter function | 转换器函数
      Returns:
      this builder | 此构建器
      Throws:
      NullPointerException - if targetField or converter is null | 如果参数为null
    • ignoreNulls

      public RecordMapper.Builder<S,T> ignoreNulls(boolean ignoreNulls)
      Sets whether to ignore null values during mapping 设置映射时是否忽略空值

      When true, source fields with null values will not be mapped to the target. For Record targets, unmapped fields will receive their type's default value.

      当为true时,源字段中的null值不会映射到目标。 对于Record目标,未映射的字段将使用其类型的默认值。

      Parameters:
      ignoreNulls - whether to ignore nulls | 是否忽略空值
      Returns:
      this builder | 此构建器
    • build

      public RecordMapper<S,T> build()
      Builds the RecordMapper 构建RecordMapper
      Returns:
      the RecordMapper | RecordMapper