Class DelegateBeanMap<T>

java.lang.Object
java.util.AbstractMap<String,Object>
org.apache.juneau.commons.bean.BeanMap<T>
org.apache.juneau.marshall.internal.DelegateBeanMap<T>
Type Parameters:
T - The class type of the wrapped bean.
All Implemented Interfaces:
Map<String,Object>, Delegate<T>

public class DelegateBeanMap<T> extends BeanMap<T>
Represents a wrapped BeanMap where property values can be overridden, removed, or reordered without affecting the underlying bean.

Provides the filterKeys(List) method for specifying the keys to keep in the bean map and in what order they should appear.

  • Constructor Details

    • DelegateBeanMap

      public DelegateBeanMap(T bean, MarshallingSession session)
      Constructor.
      Parameters:
      bean - The bean being wrapped.
      session - The bean session that created this bean map.
  • Method Details

    • addKey

      public void addKey(String key)
      Add a key in the next position.
      Parameters:
      key - The key to add.
    • entrySet

      Description copied from class: BeanMap
      Returns all the properties associated with the bean.
      Specified by:
      entrySet in interface Map<String,Object>
      Overrides:
      entrySet in class BeanMap<T>
      Returns:
      A new set.
    • filterKeys

      Remove all but the specified properties from this bean map.

      This does not affect the underlying bean.

      Parameters:
      keys - The remaining keys in the bean map (in the specified order).
      Returns:
      This object.
    • forEachProperty

      Description copied from class: BeanMap
      Performs an action on each property in this bean map.

      If a BeanSession is attached and has an active view, only properties that are visible under that view (as determined by BeanSession.isPropertyInActiveView(BeanPropertyMeta)) are visited.

      Overrides:
      forEachProperty in class BeanMap<T>
      Parameters:
      filter - The filter to apply to properties.
      action - The action.
      Returns:
      This object.
    • get

      public Object get(Object key)
      Description copied from class: BeanMap
      Gets a property on the bean.

      If an ObjectSwap-style transform is associated 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 a Date and the bean property has the DateFormat.ISO_INSTANT setting 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 Person person = new Person(); person.setBirthDate(new Date(1, 2, 3, 4, 5, 6)); // Create a marshalling context and add the ISO8601 date-time swap MarshallingContext marshallingContext = MarshallingContext.create().dateFormat(DateFormat.ISO_INSTANT).build(); // Wrap our bean in a bean map BeanMap<Person> beanMap = marshallingContext.toBeanMap(person); // Get the field as a string (i.e. "'1901-03-03T04:05:06-5000'") String birthDate = beanMap.get("birthDate");

      Specified by:
      get in interface Map<String,Object>
      Overrides:
      get in class BeanMap<T>
      Parameters:
      key - The name of the property to get.
      Returns:
      The property value.
    • getProperties

      Description copied from class: BeanMap
      Returns a simple collection of properties for this bean map.
      Overrides:
      getProperties in class BeanMap<T>
      Returns:
      A simple collection of properties for this bean map.
    • keySet

      public Set<String> keySet()
      Description copied from class: BeanMap
      Returns the names of all properties associated with the bean.

      The returned set is unmodifiable.

      Specified by:
      keySet in interface Map<String,Object>
      Overrides:
      keySet in class BeanMap<T>
    • put

      public Object put(String key, Object val)
      Description copied from class: BeanMap
      Sets a property on the bean.

      If there is a ObjectSwap associated 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 a Date and the bean property has the DateFormat.ISO_INSTANT setting 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 Person person = new Person(); // Create a marshalling context and add the ISO8601 date-time swap MarshallingContext marshallingContext = MarshallingContext.create().dateFormat(DateFormat.ISO_INSTANT).build(); // Wrap our bean in a bean map BeanMap<Person> beanMap = marshallingContext.toBeanMap(person); // Set the field beanMap.put("birthDate", "'1901-03-03T04:05:06-5000'");

      Specified by:
      put in interface Map<String,Object>
      Overrides:
      put in class BeanMap<T>
      Parameters:
      key - The name of the property to set.
      val - The value to set the property to. Can be null to set the property to null.
      Returns:
      If the beanMapPutReturnsOldValue setting is true on the session's bean configuration, then the old value of the property is returned. Otherwise, this method always returns null.
    • equals

      public boolean equals(Object o)
      Description copied from class: BeanMap
      Compares the specified object with this map for equality.

      Returns true if the given object is also a map and the two maps represent the same mappings. More formally, two maps m1 and m2 represent the same mappings if m1.entrySet().equals(m2.entrySet()).

      This implementation compares the entry sets of the two maps.

      Specified by:
      equals in interface Map<String,Object>
      Overrides:
      equals in class BeanMap<T>
      Parameters:
      o - Object to be compared for equality with this map.
      Returns:
      true if the specified object is equal to this map.
    • hashCode

      public int hashCode()
      Description copied from class: BeanMap
      Returns the hash code value for this map.

      The hash code of a map is defined to be the sum of the hash codes of each entry in the map's entrySet() view. This ensures that m1.equals(m2) implies that m1.hashCode()==m2.hashCode() for any two maps m1 and m2, as required by the general contract of Object.hashCode().

      This implementation computes the hash code from the entry set.

      Specified by:
      hashCode in interface Map<String,Object>
      Overrides:
      hashCode in class BeanMap<T>
      Returns:
      The hash code value for this map.
    • remove

      public Object remove(Object key)
      Specified by:
      remove in interface Map<String,Object>
      Overrides:
      remove in class AbstractMap<String,Object>