Class BeanMap<T>
- Type Parameters:
- T- Specifies the type of object that this map encapsulates.
- Direct Known Subclasses:
- DelegateBeanMap
Description
A wrapper that wraps Java bean instances inside of aMap interface that allows properties on the wrapped
 object can be accessed using the get() and put() methods.
 
 Use the BeanContext class to create instances of this class.
 
Bean property order
The order of the properties returned by thekeySet() and entrySet()
 methods are as follows:
 - 
      If @Beanannotation is specified on class, then the order is the same as the list of properties in the annotation.
- 
      If @Beanannotation is not specified on the class, then the order is the same as that returned by theBeanInfoclass (i.e. ordered by definition in the class).
POJO swaps
IfObjectSwaps are defined on the class types of the properties of this bean or the bean properties
 themselves, the get(Object) and put(String, Object) methods will automatically transform the
 property value to and from the serialized form.
 See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> 
- 
Field SummaryFieldsModifier and TypeFieldDescriptionTemporary holding cache for bean properties of array types when the add() method is being used.protected TThe wrapped object.The BeanMeta associated with the class of the object.Temporary holding cache for beans with read-only properties.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedBeanMap(BeanSession session, T bean, BeanMeta<T> meta) Instance of this class are instantiated through the BeanContext class.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdd a value to a collection or array property.booleancontainsKey(Object property) entrySet()Returns all the properties associated with the bean.forEachProperty(Predicate<BeanPropertyMeta> filter, Consumer<BeanPropertyMeta> action) Performs an action on each property in this bean map.forEachValue(Predicate<Object> valueFilter, BeanPropertyConsumer action) Invokes all the getters on this bean and consumes the results.Gets a property on the bean.<T2> T2Same asget(Object)but casts the value to the specific type.getBean()Returns the wrapped bean object.getBean(boolean create) Returns the wrapped bean object.final BeanSessionReturns the bean session that created this bean map.Returns theClassMetaof the wrapped bean.getMeta()Returns the metadata associated with this bean map.protected Collection<BeanPropertyMeta>Returns a simple collection of properties for this bean map.getProperties(String... fields) Extracts the specified field values from this bean and returns it as a simple Map.getProperty(String propertyName) Returns the specified property on this bean map.getPropertyMeta(String propertyName) Returns the metadata on the specified property.Same asget(Object)except bypasses the POJO filter associated with the bean property or bean filter associated with the bean class.keySet()Returns the names of all properties associated with the bean.load(Reader r, ReaderParser p) Convenience method for setting multiple property values by passing in a reader.Convenience method for setting multiple property values by passing in JSON text.Convenience method for loading this map with the contents of the specified map.static <T> BeanMap<T>of(T bean) Convenience method for wrapping a bean inside aBeanMap.Sets a property on the bean.Given a string containing variables of the form"{property}" , replaces those variables with property values in this bean.Methods inherited from class java.util.AbstractMapclear, clone, containsValue, equals, hashCode, isEmpty, putAll, remove, size, toString, valuesMethods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
beanThe wrapped object.
- 
propertyCacheTemporary holding cache for beans with read-only properties. Normally null.
- 
arrayPropertyCacheTemporary holding cache for bean properties of array types when the add() method is being used.
- 
metaThe BeanMeta associated with the class of the object.
 
- 
- 
Constructor Details- 
BeanMapInstance of this class are instantiated through the BeanContext class.- Parameters:
- session- The bean session object that created this bean map.
- bean- The bean to wrap inside this map.
- meta- The metadata associated with the bean class.
 
 
- 
- 
Method Details- 
ofConvenience method for wrapping a bean inside aBeanMap.- Type Parameters:
- T- The bean type.
- Parameters:
- bean- The bean being wrapped.
- Returns:
- A new BeanMapinstance wrapping the bean.
 
- 
getMetaReturns the metadata associated with this bean map.- Returns:
- The metadata associated with this bean map.
 
- 
getBeanSessionReturns the bean session that created this bean map.- Returns:
- The bean session that created this bean map.
 
- 
getBeanReturns the wrapped bean object.Triggers bean creation if bean has read-only properties set through a constructor defined by the @Beancannotation.- Returns:
- The inner bean object.
 
- 
getBeanReturns the wrapped bean object.If create isfalse , then this method may returnnull if the bean has read-only properties set through a constructor defined by the@Beancannotation.This method does NOT always return the bean in it's final state. Array properties temporary stored as ArrayLists are not finalized until the getBean()method is called.- Parameters:
- create- If bean hasn't been instantiated yet, then instantiate it.
- Returns:
- The inner bean object.
 
- 
putSets a property on the bean.If there is a ObjectSwapassociated with this bean property or bean property type class, then you must pass in a transformed value. For example, if the bean property type class is aDateand the bean property has theTemporalDateSwap.IsoInstantswap associated with it through the@Swap(value)annotation, the value being passed in must be a String containing an ISO8601 date-time string value.Example:// Construct a bean with a 'birthDate' Date field Personperson =new Person();// Create a bean context and add the ISO8601 date-time swap BeanContextbeanContext = BeanContext.create ().swaps(DateSwap.ISO8601DT.class ).build();// Wrap our bean in a bean map BeanMap<Person>beanMap =beanContext .toBeanMap(person );// Set the field beanMap .put("birthDate" ,"'1901-03-03T04:05:06-5000'" );- Specified by:
- putin interface- Map<String,- Object> 
- Overrides:
- putin class- AbstractMap<String,- Object> 
- Parameters:
- property- The name of the property to set.
- value- The value to set the property to.
- Returns:
- If the bean context setting beanMapPutReturnsOldValueistrue , then the old value of the property is returned. Otherwise, this method always returnsnull .
- Throws:
- RuntimeException- if any of the following occur.- BeanMapEntry does not exist on the underlying object.
- Security settings prevent access to the underlying object setter method.
- An exception occurred inside the setter method.
 
 
- 
containsKey- Specified by:
- containsKeyin interface- Map<String,- Object> 
- Overrides:
- containsKeyin class- AbstractMap<String,- Object> 
 
- 
addAdd a value to a collection or array property.As a general rule, adding to arrays is not recommended since the array must be recreate each time this method is called. - Parameters:
- property- Property name or child-element name (if- @Xml(childName)is specified).
- value- The value to add to the collection or array.
 
- 
getGets a property on the bean.If there is a ObjectSwapassociated with this bean property or bean property type class, then this method will return the transformed value. For example, if the bean property type class is aDateand the bean property has theTemporalDateSwap.IsoInstantswap associated with it through the@Swap(value)annotation, this method will return a String containing an ISO8601 date-time string value.Example:// Construct a bean with a 'birthDate' Date field Personperson =new Person();person .setBirthDate(new Date(1, 2, 3, 4, 5, 6));// Create a bean context and add the ISO8601 date-time swap BeanContextbeanContext = BeanContext.create ().swaps(DateSwap.ISO8601DT.class ).build();// Wrap our bean in a bean map BeanMap<Person>beanMap =beanContext .toBeanMap(person );// Get the field as a string (i.e. "'1901-03-03T04:05:06-5000'") StringbirthDate =beanMap .get("birthDate" );- Specified by:
- getin interface- Map<String,- Object> 
- Overrides:
- getin class- AbstractMap<String,- Object> 
- Parameters:
- property- The name of the property to get.
- Returns:
- The property value.
- Throws:
- RuntimeException- if any of the following occur.- BeanMapEntry does not exist on the underlying object.
- Security settings prevent access to the underlying object getter method.
- An exception occurred inside the getter method.
 
 
- 
getSame asget(Object)but casts the value to the specific type.- Type Parameters:
- T2- The type to cast to.
- Parameters:
- property- The name of the property to get.
- c- The type to cast to.
- Returns:
- The property value.
- Throws:
- RuntimeException- if any of the following occur.- BeanMapEntry does not exist on the underlying object.
- Security settings prevent access to the underlying object getter method.
- An exception occurred inside the getter method.
 
- ClassCastException- if property is not the specified type.
 
- 
getRawSame asget(Object)except bypasses the POJO filter associated with the bean property or bean filter associated with the bean class.- Parameters:
- property- The name of the property to get.
- Returns:
- The raw property value.
 
- 
loadConvenience method for setting multiple property values by passing in JSON text.Example:beanMap .load("{name:'John Smith',age:21}" )- Parameters:
- input- The text that will get parsed into a map and then added to this map.
- Returns:
- This object.
- Throws:
- ParseException- Malformed input encountered.
 
- 
loadConvenience method for setting multiple property values by passing in a reader.- Parameters:
- r- The text that will get parsed into a map and then added to this map.
- p- The parser to use to parse the text.
- Returns:
- This object.
- Throws:
- ParseException- Malformed input encountered.
- IOException- Thrown by- Reader .
 
- 
loadConvenience method for loading this map with the contents of the specified map.Identical to AbstractMap.putAll(Map)except as a fluent-style method.- Parameters:
- entries- The map containing the entries to add to this map.
- Returns:
- This object.
 
- 
keySetReturns the names of all properties associated with the bean.The returned set is unmodifiable. 
- 
getPropertyReturns the specified property on this bean map.Allows you to get and set an individual property on a bean without having a handle to the bean itself by using the BeanMapEntry.getValue()andBeanMapEntry.setValue(Object)methods.This method can also be used to get metadata on a property by calling the BeanMapEntry.getMeta()method.- Parameters:
- propertyName- The name of the property to look up.
- Returns:
- The bean property, or null if the bean has no such property.
 
- 
getPropertyMetaReturns the metadata on the specified property.- Parameters:
- propertyName- The name of the bean property.
- Returns:
- Metadata on the specified property, or null if that property does not exist.
 
- 
getClassMetaReturns theClassMetaof the wrapped bean.- Specified by:
- getClassMetain interface- Delegate<T>
- Returns:
- The class type of the wrapped bean.
 
- 
getPropertiesExtracts the specified field values from this bean and returns it as a simple Map.- Parameters:
- fields- The fields to extract.
- Returns:
- A new map with fields as key-value pairs.
   
 Note that modifying the values in this map will also modify the underlying bean.
 
- 
forEachValueInvokes all the getters on this bean and consumes the results.- Parameters:
- valueFilter- Filter to apply to value before applying action.
- action- The action to perform.
- Returns:
- The list of all bean property values.
 
- 
resolveVarsGiven a string containing variables of the form"{property}" , replaces those variables with property values in this bean.- Parameters:
- s- The string containing variables.
- Returns:
- A new string with variables replaced, or the same string if no variables were found.
 
- 
getPropertiesReturns a simple collection of properties for this bean map.- Returns:
- A simple collection of properties for this bean map.
 
- 
forEachPropertypublic BeanMap<T> forEachProperty(Predicate<BeanPropertyMeta> filter, Consumer<BeanPropertyMeta> action) Performs an action on each property in this bean map.- Parameters:
- filter- The filter to apply to properties.
- action- The action.
- Returns:
- This object.
 
- 
entrySetReturns all the properties associated with the bean.
 
-