Interface AttributeConverter<X,Y>
- Type Parameters:
X- the attribute type | 属性类型Y- the storage type | 存储类型
public interface AttributeConverter<X,Y>
AttributeConverter - SPI for bidirectional type conversion between two types.
属性转换器 - 用于两种类型之间双向转换的 SPI。
Implement this interface to define custom conversion logic between an attribute type and a storage type. Commonly used for entity field to database column type mapping.
实现此接口以定义属性类型和存储类型之间的自定义转换逻辑。 常用于实体字段到数据库列类型的映射。
Example | 示例:
public class JsonConverter implements AttributeConverter<MyObject, String> {
public String convertTo(MyObject attribute) {
return JsonUtils.toJson(attribute);
}
public MyObject convertFrom(String stored) {
return JsonUtils.fromJson(stored, MyObject.class);
}
}
Features | 主要功能:
- Bidirectional type conversion SPI - 双向类型转换SPI
- Generic type parameters for type safety - 泛型参数保证类型安全
- Suitable for entity-to-storage mapping - 适用于实体到存储的映射
Usage Examples | 使用示例:
AttributeConverter<LocalDate, String> conv = new AttributeConverter<>() {
public String convertTo(LocalDate date) { return date.toString(); }
public LocalDate convertFrom(String s) { return LocalDate.parse(s); }
};
Security | 安全性:
- Thread-safe: Depends on implementation - 线程安全: 取决于实现
- Null-safe: Depends on implementation, null inputs possible - 空值安全: 取决于实现,可能接收null输入
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
-
Method Details
-
convertTo
-
convertFrom
-