Interface PropertyConverter

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface PropertyConverter
Property Converter Interface - Custom property conversion strategy 属性转换器接口 - 自定义属性转换策略

Functional interface for custom property conversion during bean copy operations.

函数式接口,用于 Bean 复制操作中的自定义属性转换。

Features | 主要功能:

  • Custom conversion logic - 自定义转换逻辑
  • Access to source/target types - 访问源/目标类型
  • Property name aware - 属性名感知
  • Chainable converters (andThen) - 可链式转换器

Usage Examples | 使用示例:

// Custom converter - 自定义转换器
PropertyConverter converter = (value, srcType, tgtType, name) -> {
    if ("date".equals(name)) return formatDate(value);
    return Convert.convert(value, tgtType);
};
OpenBean.copyProperties(source, target, converter);

// Chain converters - 链式转换器
PropertyConverter chained = converter.andThen(anotherConverter);

Security | 安全性:

  • Thread-safe: Depends on implementation - 线程安全: 取决于实现
  • Null-safe: Implementation dependent - 空值安全: 取决于实现
Since:
JDK 25, opencode-base-core V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • convert

      Object convert(Object sourceValue, Class<?> sourceType, Class<?> targetType, String propertyName)
      Converts property value 转换属性值
      Parameters:
      sourceValue - source value - 源值
      sourceType - source type - 源类型
      targetType - target type - 目标类型
      propertyName - property name - 属性名
      Returns:
      the converted value - 转换后的值
    • defaultConverter

      static PropertyConverter defaultConverter()
      Default converter (uses Convert utility) 默认转换器(使用 Convert 工具)
    • identity

      static PropertyConverter identity()
      Identity converter that returns the original value 直接返回原值的转换器
    • andThen

      default PropertyConverter andThen(PropertyConverter after)
      Chained converter 链式转换器