Interface PropertyExtractor
- All Known Implementing Classes:
PropertyExtractors.ListPropertyExtractor
,PropertyExtractors.MapPropertyExtractor
,PropertyExtractors.ObjectPropertyExtractor
Property extractors define how the converter accesses object properties during nested
field navigation (e.g., "user.address.city"
). The framework uses a chain-of-responsibility
pattern, trying each registered extractor until one can handle the property access.
Extraction Strategy:
The two-phase approach ensures efficient and flexible property access:
canExtract(BeanConverter, Object, String)
: Quick check if this extractor can handle the propertyextract(BeanConverter, Object, String)
: Perform the actual property extraction
Common Use Cases:
- JavaBean properties: Standard getter methods and public fields
- Map-style access: Key-based property retrieval from Map objects
- Collection indices: Numeric access for arrays and lists
- Custom data structures: Domain-specific property access patterns
- Dynamic properties: Computed or cached property values
Implementation Example:
Registration and Usage:
Best Practices:
- Fast canExtract() checks: Use efficient type checking and avoid expensive operations
- Handle edge cases: Gracefully handle null objects and invalid property names
- Consider caching: Cache reflection results for better performance
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canExtract
(BeanConverter converter, Object o, String key) Determines if this extractor can handle property access for the given object and property name.extract
(BeanConverter converter, Object o, String key) Extracts the specified property value from the given object.
-
Method Details
-
canExtract
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.
- Parameters:
converter
- The bean converter instance (for recursive operations if needed)o
- The object to extract the property fromkey
- The property name to extract- Returns:
true
if this extractor can handle the property access,false
otherwise
-
extract
Extracts the specified property value from the given object.This method is only called after
canExtract(BeanConverter, Object, String)
returnstrue
. It should perform the actual property extraction and return the property value.- Parameters:
converter
- The bean converter instance (for recursive operations if needed)o
- The object to extract the property fromkey
- The property name to extract- Returns:
- The property value
- Throws:
PropertyNotFoundException
- if the property cannot be found on the object
-