public abstract class ContextAttributes extends Object
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 |
|---|---|
static class |
ContextAttributes.Impl |
| Constructor and Description |
|---|
ContextAttributes() |
| Modifier and Type | Method and Description |
|---|---|
abstract Object |
getAttribute(Object key)
Accessor for value of specified attribute
|
static ContextAttributes |
getEmpty()
Accessor for an empty instance of
ContextAttributes: usable
as-is, or as a starting point for building up a set of default attributes. |
abstract ContextAttributes |
withoutSharedAttribute(Object key) |
abstract ContextAttributes |
withPerCallAttribute(Object key,
Object value)
Mutator used during call (via context) to set value of "non-shared"
part of attribute set.
|
abstract ContextAttributes |
withSharedAttribute(Object key,
Object value)
Fluent factory method for creating a new instance with an additional
shared attribute.
|
abstract ContextAttributes |
withSharedAttributes(Map<?,?> attributes)
Fluent factory method for creating a new instance with specified set of
shared attributes.
|
public static ContextAttributes getEmpty()
ContextAttributes: usable
as-is, or as a starting point for building up a set of default attributes.public abstract ContextAttributes withSharedAttribute(Object key, Object value)
key - Name of the attribute to addvalue - Value of the attribute to add; may be null, in which case
attribute will be removed if it already exists.ContextAttributes that has specified change.public abstract ContextAttributes withSharedAttributes(Map<?,?> attributes)
attributes - Map of shared attributes to add, replacing any existing ones.ContextAttributes that has specified shared attributes.public abstract ContextAttributes withoutSharedAttribute(Object key)
public abstract Object getAttribute(Object key)
public abstract ContextAttributes withPerCallAttribute(Object key, Object value)
Copyright © 2008–2025 FasterXML. All rights reserved.