Class PropertyExtractors.MapPropertyExtractor
- All Implemented Interfaces:
PropertyExtractor
- Enclosing class:
- PropertyExtractors
This extractor extends PropertyExtractors.ObjectPropertyExtractor
to add special handling for
Map objects. It provides direct key-based property access and a universal size
property for Map objects.
Map-Specific Properties:
- Direct key access: Any property name that exists as a Map key
- Size property:
"size"
returnsmap.size()
Supported Types:
Works with any object implementing the Map
interface:
- HashMap, LinkedHashMap: Standard Map implementations
- TreeMap, ConcurrentHashMap: Specialized Map implementations
- Properties: Java Properties objects
- Custom Maps: Any Map implementation
Examples:
Key Priority:
Map key access takes priority over JavaBean properties. If a Map contains a key with the same name as a property/method, the Map value is returned first.
Fallback: If the property is not found as a Map key and is not "size",
delegates to PropertyExtractors.ObjectPropertyExtractor
for standard property access.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
canExtract
(BeanConverter converter, Object o, String name) Determines if this extractor can handle property access for the given object and property name.extract
(BeanConverter converter, Object o, String name) Extracts the specified property value from the given object.
-
Constructor Details
-
MapPropertyExtractor
public MapPropertyExtractor()
-
-
Method Details
-
canExtract
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 interfacePropertyExtractor
- Overrides:
canExtract
in classPropertyExtractors.ObjectPropertyExtractor
- Parameters:
converter
- The bean converter instance (for recursive operations if needed)o
- The object to extract the property fromname
- The property name to extract- Returns:
true
if this extractor can handle the property access,false
otherwise
-
extract
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)
returnstrue
. It should perform the actual property extraction and return the property value.- Specified by:
extract
in interfacePropertyExtractor
- Overrides:
extract
in classPropertyExtractors.ObjectPropertyExtractor
- Parameters:
converter
- The bean converter instance (for recursive operations if needed)o
- The object to extract the property fromname
- The property name to extract- Returns:
- The property value
-