Class OpenBean
java.lang.Object
cloud.opencode.base.reflect.bean.OpenBean
Bean Facade Entry Class
Bean门面入口类
Provides common bean operations API.
提供常用bean操作API。
Features | 主要功能:
- Property discovery - 属性发现
- Property access - 属性访问
- Bean copying - Bean复制
- Bean to Map conversion - Bean转Map
Usage Examples | 使用示例:
// Get property descriptors
Map<String, PropertyDescriptor> props = OpenBean.getPropertyDescriptors(User.class);
// Copy properties
OpenBean.copyProperties(source, target);
// Bean to Map
Map<String, Object> map = OpenBean.toMap(user);
Security | 安全性:
- Thread-safe: Yes (uses ConcurrentHashMap for caching) - 线程安全: 是(使用ConcurrentHashMap缓存)
- Null-safe: No (caller must ensure non-null arguments) - 空值安全: 否(调用方须确保非空参数)
- Since:
- JDK 25, opencode-base-reflect V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> BeanMap<T> asBeanMap(T bean) Creates a BeanMap view 创建BeanMap视图static voidClears all descriptor cache 清除所有描述符缓存static voidclearCache(Class<?> clazz) Clears the descriptor cache for a class 清除类的描述符缓存static <T> TcopyProperties(Object source, Class<T> targetClass) Copies and creates a new instance 复制并创建新实例static voidcopyProperties(Object source, Object target) Copies properties from source to target 从源复制属性到目标static voidcopyProperties(Object source, Object target, String... excludeProperties) Copies properties excluding specified ones 复制属性(排除指定属性)static <S,T> BeanCopier <S, T> createCopier(Class<S> sourceClass, Class<T> targetClass) Creates a BeanCopier 创建BeanCopierstatic <T> TCreates a bean from a Map 从Map创建beanstatic ObjectgetProperty(Object bean, String propertyName) Gets a property value 获取属性值static <T> TgetProperty(Object bean, String propertyName, Class<T> type) Gets a property value with type 获取属性值(带类型)static PropertyDescriptorgetPropertyDescriptor(Class<?> clazz, String propertyName) Gets a property descriptor by name 按名称获取属性描述符static Map<String, PropertyDescriptor> getPropertyDescriptors(Class<?> clazz) Gets all property descriptors for a class 获取类的所有属性描述符getPropertyNames(Class<?> clazz) Gets all property names 获取所有属性名getReadablePropertyNames(Class<?> clazz) Gets readable property names 获取可读属性名getWritablePropertyNames(Class<?> clazz) Gets writable property names 获取可写属性名static booleanhasProperty(Class<?> clazz, String propertyName) Checks if bean has a property 检查bean是否有属性static voidPopulates a bean from a Map 从Map填充beanstatic voidsetProperty(Object bean, String propertyName, Object value) Sets a property value 设置属性值static booleansetPropertyIfWritable(Object bean, String propertyName, Object value) Sets a property value if writable 如果可写则设置属性值Converts a bean to a Map 将bean转换为Map
-
Method Details
-
getPropertyDescriptors
Gets all property descriptors for a class 获取类的所有属性描述符- Parameters:
clazz- the class | 类- Returns:
- map of property name to descriptor | 属性名到描述符的映射
-
getPropertyDescriptor
Gets a property descriptor by name 按名称获取属性描述符- Parameters:
clazz- the class | 类propertyName- the property name | 属性名- Returns:
- the descriptor or null | 描述符或null
-
getPropertyNames
-
getReadablePropertyNames
-
getWritablePropertyNames
-
getProperty
-
getProperty
-
setProperty
-
setPropertyIfWritable
-
copyProperties
-
copyProperties
-
copyProperties
-
toMap
-
asBeanMap
Creates a BeanMap view 创建BeanMap视图- Type Parameters:
T- the bean type | bean类型- Parameters:
bean- the bean | bean- Returns:
- the BeanMap | BeanMap
-
populate
-
fromMap
-
createCopier
Creates a BeanCopier 创建BeanCopier- Type Parameters:
S- the source type | 源类型T- the target type | 目标类型- Parameters:
sourceClass- the source class | 源类targetClass- the target class | 目标类- Returns:
- the BeanCopier | BeanCopier
-
hasProperty
-
clearCache
Clears the descriptor cache for a class 清除类的描述符缓存- Parameters:
clazz- the class | 类
-
clearAllCache
public static void clearAllCache()Clears all descriptor cache 清除所有描述符缓存
-