Class PropertyExtractors.ObjectPropertyExtractor

java.lang.Object
org.apache.juneau.junit.bct.PropertyExtractors.ObjectPropertyExtractor
All Implemented Interfaces:
PropertyExtractor
Direct Known Subclasses:
PropertyExtractors.ListPropertyExtractor, PropertyExtractors.MapPropertyExtractor
Enclosing class:
PropertyExtractors

Standard JavaBean property extractor using reflection.

This extractor serves as the universal fallback for property access, implementing comprehensive JavaBean property access patterns. It tries multiple approaches to access object properties, providing maximum compatibility with different coding styles.

Property Access Order:
  1. is{Property}() - Boolean property getters (e.g., isActive())
  2. get{Property}() - Standard getter methods (e.g., getName())
  3. get(String) - Map-style property access with property name as parameter
  4. Fields - Public fields with matching names (searches inheritance hierarchy)
  5. {property}() - No-argument methods with exact property name
Examples:

// Property "name" can be accessed via: obj.getName() // Standard getter obj.name // Public field obj.name() // Method with property name obj.get("name") // Map-style getter // Property "active" (boolean) can be accessed via: obj.isActive() // Boolean getter obj.getActive() // Standard getter alternative obj.active // Public field

Compatibility: This extractor can handle any object type, making it the universal fallback. It always returns true from canExtract(BeanConverter, Object, String).

  • Constructor Details

  • Method Details

    • canExtract

      public boolean canExtract(BeanConverter converter, Object o, String name)
      Description copied from interface: PropertyExtractor
      Determines if this extractor can handle property access for the given object and property name.

      This method should perform a quick check to determine compatibility without doing expensive operations. It's called frequently during property navigation.

      Specified by:
      canExtract in interface PropertyExtractor
      Parameters:
      converter - The bean converter instance (for recursive operations if needed)
      o - The object to extract the property from
      name - The property name to extract
      Returns:
      true if this extractor can handle the property access, false otherwise
    • extract

      public Object extract(BeanConverter converter, Object o, String name)
      Description copied from interface: PropertyExtractor
      Extracts the specified property value from the given object.

      This method is only called after PropertyExtractor.canExtract(BeanConverter, Object, String) returns true. It should perform the actual property extraction and return the property value.

      Specified by:
      extract in interface PropertyExtractor
      Parameters:
      converter - The bean converter instance (for recursive operations if needed)
      o - The object to extract the property from
      name - The property name to extract
      Returns:
      The property value