Interface UserDataAware


public interface UserDataAware
Interface for objects that tend to span many steps or events where 3rd party code may want to attach private data in an early event for use in a later event. For example, consider a train. The train cannot be modified and follows a fixed route through many stations. However, it is possible to put something on the train at an early station and remove it at a later station. Now consider an action (the train) that has many lifecycle events (stations) where an early event needs to pass data to a later event. It can simply attach it to the action object using this interface.

Consider pouring a beverage. There may be many steps involved in pouring, starting with the creation of the pour object which identifies what is to be poured (the train). It then passes through many lifecycle states which may be handled by callbacks, such as locking all the required pumps, starting the pumps, recording volumes during the pour, stopping the pumps, unlocking the pumps and finally recording the final pour data before discarding the pour object. By making the pour object UserDataAware, callbacks that want to perform an action during the lock callback and clean it up during the unlock callback can store the relevant state in the pour object rather than having to track it internally across the two callbacks.

UserDataAware is intended for private data. That is, data that a 3rd party attaches at one point for use at another. It is not generally intended to allow one party to share data with another (although there are no actual limitations). For patterns that share data between different parties, consider using AttributeAware which is essentially identical, but is semantically for public data. By having these two distinct interfaces, you can convey to developers you intention around whether they should be attaching public or private data to your object.

This interface is not intended to hold data that can be serialized to json. Users should have no expectation that any data stored via this interface will be serialized. This interface does not provide JsonView management capabilities so exposing user data via json will likely result in serialization failures. Consider using ClientAttributeAware for objects that are intended to be serialized while also allowing users to attach data that should also be serialized. There is no UserDataAware equivalent as UserDataAware is for private data which would precludes the idea of sharing it with external json consumers.

Since:
1.8
Version:
2025-06-19
  • Method Details

    • setUserData

      void setUserData(String key, Object data)
      Add user data using the specified key.
      Parameters:
      key - the key for the user data
      data - the data to attach
    • getUserData

      Object getUserData(String key)
      Fetch user data for the specified key.
      Parameters:
      key - the key for the user data
    • removeUserData

      Object removeUserData(String key)
      Remove user data with the specified key.
      Parameters:
      key - the key for the user data