ObjectIdGenerator implementations:
Note
PropertyGenerator applicability is limited in one case: it can only
be used on polymorphic base types (ones indicated using JsonTypeInfo or
default typing) via class annotations: property annotation will fail due to lack
of access to property, needed to determine type of Object Id for deserialization.
This limitation may be lifted in future versions but it is the limitation at least
up to and including Jackson 2.9.
| Modifier and Type | Class and Description |
|---|---|
| private abstract static class | |
| public static class | ObjectIdGenerators.
Simple sequence-number based generator, which uses basic Java
|
| public abstract static class | ObjectIdGenerators.
Abstract marker class used to allow explicitly specifying that no generator is used; which also implies that no Object Id is to be included or used. |
| public abstract static class | ObjectIdGenerators.
Abstract place-holder class which is used to denote case where Object Identifier to use comes from a POJO property (getter method or field). |
| public static class | ObjectIdGenerators.
Implementation that will accept arbitrary (but unique) String Ids on
deserialization, and (by default) use random UUID generation similar
to |
| public static class | ObjectIdGenerators.
Implementation that just uses |
| Access | Constructor and Description |
|---|---|
| public |
| ObjectIdGenerators | back to summary |
|---|---|
| public ObjectIdGenerators() | |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | canUseFor(ObjectIdGenerator<?> gen)
Implements abstract com. Method called to check whether this generator instance can
be used for Object Ids of specific generator type and
scope; determination is based by passing a configured
"blueprint" (prototype) instance; from which the actual
instances are created (using |
| public abstract T | generateId(Object
POJO for which identifier is needed forPojo)Implements abstract com. Method used for generating a new Object Identifier to serialize for given POJO. |
| public final Class |
| _scope | back to summary |
|---|---|
| protected final Class<?> _scope | |
| Base | back to summary |
|---|---|
| protected Base(Class<?> scope) | |
| canUseFor | back to summary |
|---|---|
| public boolean canUseFor(ObjectIdGenerator<?> gen) Implements abstract com. Doc from com. Method called to check whether this generator instance can
be used for Object Ids of specific generator type and
scope; determination is based by passing a configured
"blueprint" (prototype) instance; from which the actual
instances are created (using
| |
| generateId | back to summary |
|---|---|
| public abstract T generateId(Object forPojo) Implements abstract com. Doc from com. Method used for generating a new Object Identifier to serialize for given POJO. | |
| getScope | back to summary |
|---|---|
| public final Class Implements abstract com.
| |
ints (starting with value 1) as Object Identifiers.
| Modifier and Type | Field and Description |
|---|---|
| protected transient int | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public ObjectIdGenerator | forScope(Class<?> scope)
Implements abstract com. Factory method to create a blueprint instance for specified scope. |
| public Integer | generateId(Object
POJO for which identifier is needed forPojo)Implements abstract com. Method used for generating a new Object Identifier to serialize for given POJO. |
| protected int | |
| public ObjectIdGenerator. | key(Object key)
Implements abstract com. Method for constructing key to use for ObjectId-to-POJO maps. |
| public ObjectIdGenerator | newForSerialization(Object
Serialization context object used (of type
context)com.fasterxml.jackson.databind.SerializerProvider);
may be needed by more complex generators to access contextual
information such as configuration.Implements abstract com. Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce). |
| _nextValue | back to summary |
|---|---|
| protected transient int _nextValue | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| IntSequenceGenerator | back to summary |
|---|---|
| public IntSequenceGenerator() | |
| IntSequenceGenerator | back to summary |
|---|---|
| public IntSequenceGenerator(Class<?> scope, int fv) | |
| forScope | back to summary |
|---|---|
| public ObjectIdGenerator Implements abstract com. Doc from com. Factory method to create a blueprint instance for specified scope. Generators that do not use scope may return 'this'.
| |
| generateId | back to summary |
|---|---|
| public Integer generateId(Object forPojo) Implements abstract com. Doc from com. Method used for generating a new Object Identifier to serialize for given POJO. | |
| initialValue | back to summary |
|---|---|
| protected int initialValue() | |
| key | back to summary |
|---|---|
| public ObjectIdGenerator. Implements abstract com. Doc from com. Method for constructing key to use for ObjectId-to-POJO maps.
| |
| newForSerialization | back to summary |
|---|---|
| public ObjectIdGenerator Implements abstract com. Doc from com. Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce).
Note that actual type of 'context' is
| |
| Access | Constructor and Description |
|---|---|
| public |
| None | back to summary |
|---|---|
| public None() | |
Actual implementation class is part of databind
package.
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| protected |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| PropertyGenerator | back to summary |
|---|---|
| protected PropertyGenerator(Class<?> scope) | |
UUIDGenerator for generation ids.
This generator is most useful for cases where another system creates
String Ids (of arbitrary structure, if any), and Jackson only needs to
keep track of id-to-Object mapping. Generation also works, although if
UUIDs are always used, UUIDGenerator is a better match as it
will also validate ids being used.
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | canUseFor(ObjectIdGenerator<?> gen)
Overrides com. Method called to check whether this generator instance can
be used for Object Ids of specific generator type and
scope; determination is based by passing a configured
"blueprint" (prototype) instance; from which the actual
instances are created (using |
| public ObjectIdGenerator | forScope(Class<?> scope)
Implements abstract com. Factory method to create a blueprint instance for specified scope. |
| public String | generateId(Object
POJO for which identifier is needed forPojo)Implements abstract com. Method used for generating a new Object Identifier to serialize for given POJO. |
| public ObjectIdGenerator. | key(Object key)
Implements abstract com. Method for constructing key to use for ObjectId-to-POJO maps. |
| public ObjectIdGenerator | newForSerialization(Object
Serialization context object used (of type
context)com.fasterxml.jackson.databind.SerializerProvider);
may be needed by more complex generators to access contextual
information such as configuration.Implements abstract com. Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce). |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| StringIdGenerator | back to summary |
|---|---|
| public StringIdGenerator() | |
| StringIdGenerator | back to summary |
|---|---|
| private StringIdGenerator(Class<?> scope) | |
| canUseFor | back to summary |
|---|---|
| public boolean canUseFor(ObjectIdGenerator<?> gen) Overrides com. Doc from com. Method called to check whether this generator instance can
be used for Object Ids of specific generator type and
scope; determination is based by passing a configured
"blueprint" (prototype) instance; from which the actual
instances are created (using
| |
| forScope | back to summary |
|---|---|
| public ObjectIdGenerator Implements abstract com. Doc from com. Factory method to create a blueprint instance for specified scope. Generators that do not use scope may return 'this'.
| |
| generateId | back to summary |
|---|---|
| public String generateId(Object forPojo) Implements abstract com. Doc from com. Method used for generating a new Object Identifier to serialize for given POJO. | |
| key | back to summary |
|---|---|
| public ObjectIdGenerator. Implements abstract com. Doc from com. Method for constructing key to use for ObjectId-to-POJO maps.
| |
| newForSerialization | back to summary |
|---|---|
| public ObjectIdGenerator Implements abstract com. Doc from com. Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce).
Note that actual type of 'context' is
| |
java.util.UUID s as reliably
unique identifiers: downside is that resulting String is
36 characters long.
One difference to other generators is that scope is always
set as Object.class (regardless of arguments): this
because UUIDs are globally unique, and scope has no meaning.
| Modifier and Type | Field and Description |
|---|---|
| private static final long |
| Access | Constructor and Description |
|---|---|
| public | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | canUseFor(ObjectIdGenerator<?> gen)
Overrides com. Since UUIDs are always unique, let's fully ignore scope definition |
| public ObjectIdGenerator | forScope(Class<?> scope)
Implements abstract com. Can just return base instance since this is essentially scopeless |
| public UUID | generateId(Object
POJO for which identifier is needed forPojo)Implements abstract com. Method used for generating a new Object Identifier to serialize for given POJO. |
| public ObjectIdGenerator. | key(Object key)
Implements abstract com. Method for constructing key to use for ObjectId-to-POJO maps. |
| public ObjectIdGenerator | newForSerialization(Object
Serialization context object used (of type
context)com.fasterxml.jackson.databind.SerializerProvider);
may be needed by more complex generators to access contextual
information such as configuration.Implements abstract com. Can just return base instance since this is essentially scopeless |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| UUIDGenerator | back to summary |
|---|---|
| public UUIDGenerator() | |
| UUIDGenerator | back to summary |
|---|---|
| private UUIDGenerator(Class<?> scope) | |
| canUseFor | back to summary |
|---|---|
| public boolean canUseFor(ObjectIdGenerator<?> gen) Overrides com. Since UUIDs are always unique, let's fully ignore scope definition
| |
| forScope | back to summary |
|---|---|
| public ObjectIdGenerator Implements abstract com. Can just return base instance since this is essentially scopeless
| |
| generateId | back to summary |
|---|---|
| public UUID generateId(Object forPojo) Implements abstract com. Doc from com. Method used for generating a new Object Identifier to serialize for given POJO. | |
| key | back to summary |
|---|---|
| public ObjectIdGenerator. Implements abstract com. Doc from com. Method for constructing key to use for ObjectId-to-POJO maps.
| |
| newForSerialization | back to summary |
|---|---|
| public ObjectIdGenerator Implements abstract com. Can just return base instance since this is essentially scopeless
| |