Interface UserDataAware
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 Summary
Modifier and TypeMethodDescriptiongetUserData
(String key) Fetch user data for the specified key.removeUserData
(String key) Remove user data with the specified key.void
setUserData
(String key, Object data) Add user data using the specified key.
-
Method Details
-
setUserData
Add user data using the specified key.- Parameters:
key
- the key for the user datadata
- the data to attach
-
getUserData
Fetch user data for the specified key.- Parameters:
key
- the key for the user data
-
removeUserData
Remove user data with the specified key.- Parameters:
key
- the key for the user data
-