Interface ClientAttributeAware

All Known Implementing Classes:
DelayFuture, FailedFuture, FutureWork, ParallelFuture, SequencedFuture, Trouble

public interface ClientAttributeAware
Interface that allows 3rd parties to attach attributes to a core ClientAttributeAware object in a way that allows the attribute data to be serialize to json. This differs from AttributeAware which is not compatible with json serialization and intended for java access only. Some objects may be both ClientAttributeAware and AttributeAware, where client attributes are exposed via endpoints where non-client attributes are not.

This interface requires access to a Map to back the attributes. The values in the map will always be wrapped in a JsonViewWrapper object so the map should not be accessed directly. The interface will return the original wrapped data for use in java, while returning the wrapped view of the data for json serialization. This allows every object placed into the map to have a custom json view applied, which avoids the view of the ClientAttributeAware object from being applied to the data in the attribute map.

There is support for adding attributes which will not be serialized to json by using the setHiddenClientAttribute(String, Object) method. This effectively allows ClientAttributeAware to be used as AttributeAware which doesn't support json serialization.

Since:
8
Version:
8
  • Method Details

    • _getClientAttributeMap

      Map<String,JsonViewWrapper> _getClientAttributeMap()
      Return the Map that backs the attributes. This is used within the ClientAttributeAware interface and should never be accessed directly.
      Since:
      8
    • setClientAttribute

      default void setClientAttribute(String name, Object value, Class<?> view)
      Sets the attribute for the given name and specifies the view used to serialize the attribute to json.
      Parameters:
      name - the attribute name
      value - the attribute value
      view - the json view used to serialize the value
      Since:
      8
    • setHiddenClientAttribute

      default void setHiddenClientAttribute(String name, Object value)
      Sets the attribute for the given name using an internal view that will prevent the value from being serialized to json. This allows ClientAttributeAware to be used similar to AttributeAware for objects that only provide ClientAttributeAware support.
      Parameters:
      name - the attribute name
      value - the attribute value
      Since:
      8
    • getClientAttribute

      default Object getClientAttribute(String name)
      Given a name, return the associated attribute value.
      Parameters:
      name - the attribute name
      Returns:
      the value of the attribute, or null if it doesn't exist
      Since:
      8
    • removeClientAttribute

      default Object removeClientAttribute(String name)
      Remove the attribute with the specified name.
      Parameters:
      name - the attribute to remove
      Returns:
      the value of the attribute being removed, or null if it didn't exist
      Since:
      8
    • getClientAttributes

      default Map<String,JsonViewWrapper> getClientAttributes()
      Return the attributes for json serialization. This returns null if the map is empty in order to minimize payload sizes. This has no default JsonView . If a view is required, override the method and apply the correct view.

      The default json property name is attrs .

      This should not be used to directly access or manipulate the attributes map.

      Since:
      8