Class BeanPath

java.lang.Object
cloud.opencode.base.reflect.bean.BeanPath

public final class BeanPath extends Object
Bean Path Navigator Bean路径导航器

Navigates nested bean properties using path expressions. Supports dot notation (e.g., "user.address.city").

使用路径表达式导航嵌套bean属性。 支持点号表示法(如 "user.address.city")。

Features | 主要功能:

  • Dot notation path navigation - 点号表示法路径导航
  • Indexed property access (list, array, map) - 索引属性访问(列表、数组、映射)
  • Nested property read/write - 嵌套属性读写
  • Path existence checking - 路径存在检查

Usage Examples | 使用示例:

// Get nested property
String city = BeanPath.get(user, "address.city", String.class);

// Set nested property
BeanPath.set(user, "address.city", "Beijing");

// Indexed access
Object item = BeanPath.get(order, "items[0].name");

Security | 安全性:

  • Thread-safe: Yes (stateless utility class) - 线程安全: 是(无状态工具类)
  • Null-safe: Partially (returns null for null bean or intermediate null) - 空值安全: 部分(null bean或中间null返回null)
Since:
JDK 25, opencode-base-reflect V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • get

      public static Object get(Object bean, String path)
      Gets a nested property value 获取嵌套属性值
      Parameters:
      bean - the root bean | 根bean
      path - the property path (e.g., "user.address.city") | 属性路径
      Returns:
      the value | 值
    • get

      public static <T> T get(Object bean, String path, Class<T> type)
      Gets a nested property value with type 获取嵌套属性值(带类型)
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      bean - the root bean | 根bean
      path - the property path | 属性路径
      type - the expected type | 期望类型
      Returns:
      the value | 值
    • getOrDefault

      public static <T> T getOrDefault(Object bean, String path, T defaultValue)
      Gets a nested property value or default 获取嵌套属性值或默认值
      Type Parameters:
      T - the value type | 值类型
      Parameters:
      bean - the root bean | 根bean
      path - the property path | 属性路径
      defaultValue - the default value | 默认值
      Returns:
      the value or default | 值或默认值
    • set

      public static void set(Object bean, String path, Object value)
      Sets a nested property value 设置嵌套属性值
      Parameters:
      bean - the root bean | 根bean
      path - the property path | 属性路径
      value - the value to set | 要设置的值
    • hasPath

      public static boolean hasPath(Object bean, String path)
      Checks if a path exists and is readable 检查路径是否存在且可读
      Parameters:
      bean - the root bean | 根bean
      path - the property path | 属性路径
      Returns:
      true if path is valid | 如果路径有效返回true
    • getPathValues

      public static List<Object> getPathValues(Object bean, String path)
      Gets all values along a path 获取路径上的所有值
      Parameters:
      bean - the root bean | 根bean
      path - the property path | 属性路径
      Returns:
      list of values (including intermediate values) | 值列表(包括中间值)
    • copy

      public static void copy(Object source, String sourcePath, Object target, String targetPath)
      Copies a property from one path to another 从一个路径复制属性到另一个路径
      Parameters:
      source - the source bean | 源bean
      sourcePath - the source path | 源路径
      target - the target bean | 目标bean
      targetPath - the target path | 目标路径