Class RecordMapper<S,T>
java.lang.Object
cloud.opencode.base.reflect.record.RecordMapper<S,T>
- Type Parameters:
S- the source type | 源类型T- the target type | 目标类型
Record Mapper for advanced Record/Bean mapping
Record映射器 - 高级Record/Bean映射
Provides advanced mapping between Records and Beans with support for field renaming, exclusion, type conversion, and batch operations.
提供Record和Bean之间的高级映射,支持字段重命名、排除、类型转换和批量操作。
Features | 主要功能:
- Record to Record mapping - Record到Record映射
- Record to Bean mapping - Record到Bean映射
- Bean to Record mapping - Bean到Record映射
- Bean to Bean mapping - Bean到Bean映射
- Field renaming via map() - 通过map()重命名字段
- Field exclusion via exclude() - 通过exclude()排除字段
- Custom type converters - 自定义类型转换器
- Null value handling - 空值处理
- Batch mapping - 批量映射
Usage Examples | 使用示例:
// Simple Record to Record mapping
RecordMapper<UserDTO, User> mapper = RecordMapper.builder(UserDTO.class, User.class)
.map("userName", "name")
.exclude("password")
.convert("age", v -> Integer.parseInt(v.toString()))
.ignoreNulls(true)
.build();
User user = mapper.map(dto);
List<User> users = mapper.mapAll(dtos);
Security | 安全性:
- Thread-safe: Yes (immutable after construction) - 线程安全: 是(构造后不可变)
- Null-safe: No (source must not be null) - 空值安全: 否(源不能为null)
Performance | 性能特性:
- Time complexity: O(n) per mapping where n is the number of fields - 时间复杂度: 每次映射O(n),n为字段数
- Space complexity: O(n) for the field mapping configuration - 空间复杂度: O(n)用于字段映射配置
- Since:
- JDK 25, opencode-base-reflect V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for RecordMapper RecordMapper构建器 -
Method Summary
Modifier and TypeMethodDescriptionstatic <S,T> RecordMapper.Builder <S, T> Creates a new RecordMapper builder 创建新的RecordMapper构建器Maps a source object to a target object 将源对象映射为目标对象mapAll(Collection<? extends S> sources) Maps a collection of source objects to a list of target objects 将源对象集合映射为目标对象列表
-
Method Details
-
builder
Creates a new RecordMapper builder 创建新的RecordMapper构建器- Type Parameters:
S- the source type | 源类型T- the target type | 目标类型- Parameters:
sourceType- the source type | 源类型targetType- the target type | 目标类型- Returns:
- the builder | 构建器
- Throws:
NullPointerException- if sourceType or targetType is null | 如果sourceType或targetType为null
-
map
Maps a source object to a target object 将源对象映射为目标对象- Parameters:
source- the source object | 源对象- Returns:
- the mapped target object | 映射后的目标对象
- Throws:
NullPointerException- if source is null | 如果源对象为nullOpenReflectException- if mapping fails | 如果映射失败
-
mapAll
Maps a collection of source objects to a list of target objects 将源对象集合映射为目标对象列表- Parameters:
sources- the source collection | 源集合- Returns:
- the mapped target list | 映射后的目标列表
- Throws:
NullPointerException- if sources is null | 如果源集合为null
-