Class ContextAttributes
- java.lang.Object
-
- com.fasterxml.jackson.databind.cfg.ContextAttributes
-
- Direct Known Subclasses:
ContextAttributes.Impl
public abstract class ContextAttributes extends java.lang.ObjectHelper class used for storing and accessing per-call attributes. Storage is two-layered: at higher precedence, we have actual per-call (ObjectMapper.readValueorObjectMapper.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)orwithSharedAttribute(Object, Object), starting with "empty" instance (seegetEmpty()). For example:ContextAttributes attrs = ContextAttributes.getEmpty() .withSharedAttribute("foo", "bar") .withSharedAttribute("attr2", "value2");- Since:
- 2.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classContextAttributes.Impl
-
Constructor Summary
Constructors Constructor Description ContextAttributes()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.lang.ObjectgetAttribute(java.lang.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 ContextAttributeswithoutSharedAttribute(java.lang.Object key)abstract ContextAttributeswithPerCallAttribute(java.lang.Object key, java.lang.Object value)Mutator used during call (via context) to set value of "non-shared" part of attribute set.abstract ContextAttributeswithSharedAttribute(java.lang.Object key, java.lang.Object value)Fluent factory method for creating a new instance with an additional shared attribute.abstract ContextAttributeswithSharedAttributes(java.util.Map<?,?> attributes)Fluent factory method for creating a new instance with specified set of shared attributes.
-
-
-
Method Detail
-
getEmpty
public static ContextAttributes getEmpty()
Accessor for an empty instance ofContextAttributes: usable as-is, or as a starting point for building up a set of default attributes.
-
withSharedAttribute
public abstract ContextAttributes withSharedAttribute(java.lang.Object key, java.lang.Object value)
Fluent factory method for creating a new instance with an additional shared attribute.- Parameters:
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.- Returns:
- New instance of
ContextAttributesthat has specified change.
-
withSharedAttributes
public abstract ContextAttributes withSharedAttributes(java.util.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- Parameters:
attributes- Map of shared attributes to add, replacing any existing ones.- Returns:
- New instance of
ContextAttributesthat has specified shared attributes.
-
withoutSharedAttribute
public abstract ContextAttributes withoutSharedAttribute(java.lang.Object key)
-
getAttribute
public abstract java.lang.Object getAttribute(java.lang.Object key)
Accessor for value of specified attribute
-
withPerCallAttribute
public abstract ContextAttributes withPerCallAttribute(java.lang.Object key, java.lang.Object value)
Mutator used during call (via context) to set value of "non-shared" part of attribute set.
-
-