Class BeanCopier<S,T>

java.lang.Object
cloud.opencode.base.reflect.bean.BeanCopier<S,T>
Type Parameters:
S - the source type | 源类型
T - the target type | 目标类型

public class BeanCopier<S,T> extends Object
Bean Copier Bean复制器

High-performance bean property copier.

高性能bean属性复制器。

Features | 主要功能:

  • Property mapping and renaming - 属性映射和重命名
  • Custom converters - 自定义转换器
  • Property exclusion and null filtering - 属性排除和null过滤
  • Batch list copying - 批量列表复制

Usage Examples | 使用示例:

BeanCopier<UserDTO, User> copier = BeanCopier.builder(UserDTO.class, User.class)
    .map("userName", "name")
    .exclude("password")
    .ignoreNulls(true)
    .build();
User user = copier.copy(dto);

Security | 安全性:

  • Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
  • Null-safe: Configurable (ignoreNulls option) - 空值安全: 可配置(ignoreNulls选项)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • builder

      public static <S,T> BeanCopier.Builder<S,T> builder(Class<S> sourceClass, Class<T> targetClass)
      Creates a BeanCopier builder 创建BeanCopier构建器
      Type Parameters:
      S - the source type | 源类型
      T - the target type | 目标类型
      Parameters:
      sourceClass - the source class | 源类
      targetClass - the target class | 目标类
      Returns:
      the builder | 构建器
    • create

      public static <S,T> BeanCopier<S,T> create(Class<S> sourceClass, Class<T> targetClass)
      Creates a simple BeanCopier 创建简单BeanCopier
      Type Parameters:
      S - the source type | 源类型
      T - the target type | 目标类型
      Parameters:
      sourceClass - the source class | 源类
      targetClass - the target class | 目标类
      Returns:
      the copier | 复制器
    • copy

      public void copy(S source, T target)
      Copies properties from source to target 从源复制属性到目标
      Parameters:
      source - the source object | 源对象
      target - the target object | 目标对象
    • copy

      public T copy(S source)
      Copies and creates a new target instance 复制并创建新的目标实例
      Parameters:
      source - the source object | 源对象
      Returns:
      the new target instance | 新的目标实例
    • copyList

      public List<T> copyList(List<S> sources)
      Copies a list of objects 复制对象列表
      Parameters:
      sources - the source list | 源列表
      Returns:
      the target list | 目标列表
    • getSourceClass

      public Class<S> getSourceClass()
      Gets the source class 获取源类
      Returns:
      the source class | 源类
    • getTargetClass

      public Class<T> getTargetClass()
      Gets the target class 获取目标类
      Returns:
      the target class | 目标类