Top Description Inners Constructors Methods
tools.jackson.databind.cfg

public abstract Class ContextAttributes

extends Object
implements Snapshottable<ContextAttributes>
Class Inheritance
All Implemented Interfaces
tools.jackson.core.util.Snapshottable
Known Direct Subclasses
tools.jackson.databind.cfg.ContextAttributes.Impl
Imports
java.util.*, tools.jackson.core.util.Snapshottable

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract Object
getAttribute(Object key)

Accessor for value of specified attribute

public 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.

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 of ContextAttributes that has specified change.
withSharedAttribute
(Object
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 of ContextAttributes that has specified shared attributes.
withSharedAttributes
(Map<?, ?>
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ContextAttributesback to summary
public ContextAttributes()

Method Detail

getAttributeback to summary
public abstract Object getAttribute(Object key)

Accessor for value of specified attribute

getEmptyback to summary
public 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.

withoutSharedAttributeback to summary
public abstract ContextAttributes withoutSharedAttribute(Object key)
withPerCallAttributeback 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.

withSharedAttributeback to summary
public abstract ContextAttributes withSharedAttribute(Object key, Object value)

Fluent factory method for creating a new instance with an additional shared attribute.

Parameters
key:Object

Name of the attribute to add

value:Object

Value of the attribute to add; may be null, in which case attribute will be removed if it already exists.

Returns:ContextAttributes

New instance of ContextAttributes that has specified change.

withSharedAttributesback 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

Parameters
attributes:Map<?, ?>

Map of shared attributes to add, replacing any existing ones.

Returns:ContextAttributes

New instance of ContextAttributes that has specified shared attributes.

tools.jackson.databind.cfg back to summary

public Class ContextAttributes.Impl

extends ContextAttributes
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
protected transient Map<Object, Object>
_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.Impl
protected static final Object
private static final long

Constructor Summary

AccessConstructor and Description
protected
Impl(Map<?, ?> shared)

protected
Impl(Map<?, ?> shared, Map<Object, Object> nonShared)

Method Summary

Modifier and TypeMethod and Description
private Map<Object, Object>
_copy(Map<?, ?> src)

public Object
getAttribute(Object key)

Implements abstract tools.jackson.databind.cfg.ContextAttributes.getAttribute.

Accessor for value of specified attribute

public static ContextAttributes
getEmpty()

Hides tools.jackson.databind.cfg.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.

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.jackson.core.util.Snapshottable.snapshot.

Method to call to get an instance that may not be modified through any other object, including `this`.

public ContextAttributes
public ContextAttributes
withPerCallAttribute(Object key, Object value)

Implements abstract tools.jackson.databind.cfg.ContextAttributes.withPerCallAttribute.

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.jackson.databind.cfg.ContextAttributes.withSharedAttribute.

Fluent factory method for creating a new instance with an additional shared attribute.

public ContextAttributes
withSharedAttributes(Map<?, ?> shared)

Implements abstract tools.jackson.databind.cfg.ContextAttributes.withSharedAttributes.

Fluent factory method for creating a new instance with specified set of shared attributes.

Field Detail

_nonSharedback 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, because we need to be able to modify contents, and wildcard type would complicate that access.

_sharedback to summary
protected final Map<?, ?> _shared

Shared attributes that we cannot modify in-place.

EMPTYback to summary
protected static final ContextAttributes.Impl EMPTY
NULL_SURROGATEback to summary
protected static final Object NULL_SURROGATE
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

Implback to summary
protected Impl(Map<?, ?> shared)
Implback to summary
protected Impl(Map<?, ?> shared, Map<Object, Object> nonShared)

Method Detail

_copyback to summary
private Map<Object, Object> _copy(Map<?, ?> src)
getAttributeback to summary
public Object getAttribute(Object key)

Implements abstract tools.jackson.databind.cfg.ContextAttributes.getAttribute.

Doc from tools.jackson.databind.cfg.ContextAttributes.getAttribute.

Accessor for value of specified attribute

Annotations
@Override
getEmptyback to summary
public static ContextAttributes getEmpty()

Hides tools.jackson.databind.cfg.ContextAttributes.getEmpty.

Doc from tools.jackson.databind.cfg.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.

nonSharedInstanceback to summary
protected ContextAttributes nonSharedInstance(Object key, Object value)

Overridable method that creates initial non-shared instance, with the first explicit set value.

snapshotback to summary
public ContextAttributes snapshot()

Implements tools.jackson.core.util.Snapshottable.snapshot.

Doc from tools.jackson.core.util.Snapshottable.snapshot.

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.

Annotations
@Override
withoutSharedAttributeback to summary
public ContextAttributes withoutSharedAttribute(Object key)

Implements abstract tools.jackson.databind.cfg.ContextAttributes.withoutSharedAttribute.

Annotations
@Override
withPerCallAttributeback to summary
public ContextAttributes withPerCallAttribute(Object key, Object value)

Implements abstract tools.jackson.databind.cfg.ContextAttributes.withPerCallAttribute.

Doc from tools.jackson.databind.cfg.ContextAttributes.withPerCallAttribute.

Mutator used during call (via context) to set value of "non-shared" part of attribute set.

Annotations
@Override
withSharedAttributeback to summary
public ContextAttributes withSharedAttribute(Object key, Object value)

Implements abstract tools.jackson.databind.cfg.ContextAttributes.withSharedAttribute.

Doc from tools.jackson.databind.cfg.ContextAttributes.withSharedAttribute.

Fluent factory method for creating a new instance with an additional shared attribute.

Annotations
@Override
withSharedAttributesback to summary
public ContextAttributes withSharedAttributes(Map<?, ?> shared)

Implements abstract tools.jackson.databind.cfg.ContextAttributes.withSharedAttributes.

Doc from tools.jackson.databind.cfg.ContextAttributes.withSharedAttributes.

Fluent factory method for creating a new instance with specified set of shared attributes. Any shared attributes that already exist will be replaced

Annotations
@Override