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");
| Modifier and Type | Class and Description |
|---|---|
| public static class |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract Object | |
| public static ContextAttributes | getEmpty()
Accessor for an empty instance of |
| public abstract ContextAttributes | |
| public abstract ContextAttributes | withPerCallAttribute(Object key, Object value)
Mutator used during call (via context) to set value of "non-shared" part of attribute set. |
| public abstract ContextAttributes | Returns: New instance ofContextAttributes that has specified change.Name of the attribute to add key, Object Value of the attribute to add; may be null, in which case
attribute will be removed if it already exists. value)Fluent factory method for creating a new instance with an additional shared attribute. |
| public abstract ContextAttributes | Returns: New instance ofContextAttributes that has specified shared attributes.Map of shared attributes to add, replacing any existing ones. attributes)Fluent factory method for creating a new instance with specified set of shared attributes. |
| ContextAttributes | back to summary |
|---|---|
| public ContextAttributes() | |
| getAttribute | back to summary |
|---|---|
| public abstract Object getAttribute(Object key) Accessor for value of specified attribute | |
| getEmpty | back to summary |
|---|---|
| public static ContextAttributes getEmpty() Accessor for an empty instance of | |
| withoutSharedAttribute | back to summary |
|---|---|
| public abstract ContextAttributes withoutSharedAttribute(Object key) | |
| withPerCallAttribute | back to summary |
|---|---|
| public abstract ContextAttributes withPerCallAttribute(Object key, Object value) Mutator used during call (via context) to set value of "non-shared" part of attribute set. | |
| withSharedAttribute | back to summary |
|---|---|
| public abstract ContextAttributes withSharedAttribute(Object key, Object value) Fluent factory method for creating a new instance with an additional shared attribute.
| |
| withSharedAttributes | back to summary |
|---|---|
| public abstract ContextAttributes withSharedAttributes(Map<?, ?> attributes) Fluent factory method for creating a new instance with specified set of shared attributes. Any shared attributes that already exist will be replaced
| |
| Modifier and Type | Field and Description |
|---|---|
| protected transient Map | _nonShared
Per-call attributes that we can directly modify, since they are not shared between threads. |
| protected final Map | _shared
Shared attributes that we cannot modify in-place. |
| protected static final ContextAttributes. | |
| protected static final Object | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| protected | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| private Map | |
| public Object | getAttribute(Object key)
Implements abstract tools. Accessor for value of specified attribute |
| public static ContextAttributes | getEmpty()
Hides tools. Accessor for an empty instance of |
| protected ContextAttributes | nonSharedInstance(Object key, Object value)
Overridable method that creates initial non-shared instance, with the first explicit set value. |
| public ContextAttributes | snapshot()
Implements tools. Method to call to get an instance that may not be modified through any other object, including `this`. |
| public ContextAttributes | withoutSharedAttribute(Object key)
Implements abstract tools.
|
| public ContextAttributes | withPerCallAttribute(Object key, Object value)
Implements abstract tools. Mutator used during call (via context) to set value of "non-shared" part of attribute set. |
| public ContextAttributes | withSharedAttribute(Object key, Object value)
Implements abstract tools. Fluent factory method for creating a new instance with an additional shared attribute. |
| public ContextAttributes | withSharedAttributes(Map<?, ?> shared)
Implements abstract tools. Fluent factory method for creating a new instance with specified set of shared attributes. |
| _nonShared | back to summary |
|---|---|
| protected transient Map<Object, Object> _nonShared Per-call attributes that we can directly modify, since they are not shared between threads. Note typed as Object-to-Object, unlike | |
| _shared | back to summary |
|---|---|
| protected final Map<?, ?> _shared Shared attributes that we cannot modify in-place. | |
| EMPTY | back to summary |
|---|---|
| protected static final ContextAttributes. | |
| NULL_SURROGATE | back to summary |
|---|---|
| protected static final Object NULL_SURROGATE | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| Impl | back to summary |
|---|---|
| protected Impl(Map<?, ?> shared) | |
| Impl | back to summary |
|---|---|
| protected Impl(Map<?, ?> shared, Map<Object, Object> nonShared) | |
| _copy | back to summary |
|---|---|
| private Map | |
| getAttribute | back to summary |
|---|---|
| public Object getAttribute(Object key) Implements abstract tools. Doc from tools. Accessor for value of specified attribute
| |
| getEmpty | back to summary |
|---|---|
| public static ContextAttributes getEmpty() Hides tools. Doc from tools. Accessor for an empty instance of | |
| nonSharedInstance | back to summary |
|---|---|
| protected ContextAttributes nonSharedInstance(Object key, Object value) Overridable method that creates initial non-shared instance, with the first explicit set value. | |
| snapshot | back to summary |
|---|---|
| public ContextAttributes snapshot() Implements tools. Doc from tools. Method to call to get an instance that may not be modified through any other object, including `this`. That instance may be `this` if (and only if) this instance is effectively immutable (unmodifiable) through its API: if this is not the case, a new copy with same configuration must be created and returned.
| |
| withoutSharedAttribute | back to summary |
|---|---|
| public ContextAttributes withoutSharedAttribute(Object key) Implements abstract tools.
| |
| withPerCallAttribute | back to summary |
|---|---|
| public ContextAttributes withPerCallAttribute(Object key, Object value) Implements abstract tools. Doc from tools. Mutator used during call (via context) to set value of "non-shared" part of attribute set.
| |
| withSharedAttribute | back to summary |
|---|---|
| public ContextAttributes withSharedAttribute(Object key, Object value) Implements abstract tools. Doc from tools. Fluent factory method for creating a new instance with an additional shared attribute.
| |
| withSharedAttributes | back to summary |
|---|---|
| public ContextAttributes withSharedAttributes(Map<?, ?> shared) Implements abstract tools. Doc from tools. Fluent factory method for creating a new instance with specified set of shared attributes. Any shared attributes that already exist will be replaced
| |