Interface PropertyAccessor
public interface PropertyAccessor
Property Accessor SPI
属性访问器SPI
Provides a service provider interface for property access.
为属性访问提供服务提供者接口。
Features | 主要功能:
- SPI for custom property access on any object type - 用于任意对象类型自定义属性访问的SPI
- Read and optional write support - 读取和可选写入支持
- Target type filtering via getSpecificTargetClasses - 通过getSpecificTargetClasses进行目标类型过滤
Usage Examples | 使用示例:
public class JsonPropertyAccessor implements PropertyAccessor {
@Override
public Class<?>[] getSpecificTargetClasses() {
return new Class<?>[]{ JsonNode.class };
}
@Override
public boolean canRead(Object target, String name) {
return target instanceof JsonNode jn && jn.has(name);
}
@Override
public Object read(Object target, String name) {
return ((JsonNode) target).get(name);
}
}
Security | 安全性:
- Thread-safe: Depends on implementation - 线程安全: 取决于实现
- Null-safe: Depends on implementation - 空值安全: 取决于实现
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if this accessor can read the property 检查此访问器是否可以读取属性default booleanCheck if this accessor can write the property 检查此访问器是否可以写入属性Class<?>[]Get the target types this accessor supports 获取此访问器支持的目标类型Read the property value 读取属性值default voidWrite the property value 写入属性值
-
Method Details
-
getSpecificTargetClasses
Class<?>[] getSpecificTargetClasses()Get the target types this accessor supports 获取此访问器支持的目标类型- Returns:
- the supported types, or null for all types | 支持的类型,null表示所有类型
-
canRead
-
read
-
canWrite
-
write
-