java.lang.Object
tools.jackson.databind.cfg.ContextAttributes
- All Implemented Interfaces:
Snapshottable<ContextAttributes>
- Direct Known Subclasses:
ContextAttributes.Impl
Helper class used for storing and accessing per-call attributes.
Storage is two-layered: at higher precedence, we have actual per-call
(
ObjectMapper.readValue or ObjectMapper.writeValue)
attributes; and at lower precedence, default attributes that may be
defined for Object readers and writers.
Note that the way mutability is implemented differs between kinds of attributes, to account for thread-safety: per-call attributes are handled assuming that instances are never shared, whereas changes to per-reader/per-writer attributes are made assuming sharing, by creating new copies instead of modifying state. This allows sharing of default values without per-call copying, but requires two-level lookup on access.
To set default attributes, use withSharedAttributes(Map)
or withSharedAttribute(Object, Object), starting with
"empty" instance (see getEmpty()). For example:
ContextAttributes attrs = ContextAttributes.getEmpty()
.withSharedAttribute("foo", "bar")
.withSharedAttribute("attr2", "value2");
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ObjectgetAttribute(Object key) Accessor for value of specified attributestatic ContextAttributesgetEmpty()Accessor for an empty instance ofContextAttributes: usable as-is, or as a starting point for building up a set of default attributes.abstract ContextAttributesabstract ContextAttributeswithPerCallAttribute(Object key, Object value) Mutator used during call (via context) to set value of "non-shared" part of attribute set.abstract ContextAttributeswithSharedAttribute(Object key, Object value) Fluent factory method for creating a new instance with an additional shared attribute.abstract ContextAttributeswithSharedAttributes(Map<?, ?> attributes) Fluent factory method for creating a new instance with specified set of shared attributes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface tools.jackson.core.util.Snapshottable
snapshot
-
Constructor Details
-
ContextAttributes
public ContextAttributes()
-
-
Method Details
-
getEmpty
Accessor for an empty instance ofContextAttributes: usable as-is, or as a starting point for building up a set of default attributes. -
getAttribute
Accessor for value of specified attribute -
withPerCallAttribute
Mutator used during call (via context) to set value of "non-shared" part of attribute set.
-