Top Description Inners Constructors Methods
com.fasterxml.jackson.annotation

public Class ObjectIdGenerators

extends Object
Class Inheritance
Imports
java.util.UUID

Container class for standard 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
ObjectIdGenerators.Base<T>

Shared base class for concrete implementations.

public static class
ObjectIdGenerators.IntSequenceGenerator

Simple sequence-number based generator, which uses basic Java ints (starting with value 1) as Object Identifiers.

public abstract static class
ObjectIdGenerators.None

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

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

Implementation that will accept arbitrary (but unique) String Ids on deserialization, and (by default) use random UUID generation similar to UUIDGenerator for generation ids.

public static class
ObjectIdGenerators.UUIDGenerator

Implementation that just uses java.util.UUIDs as reliably unique identifiers: downside is that resulting String is 36 characters long.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ObjectIdGeneratorsback to summary
public ObjectIdGenerators()
com.fasterxml.jackson.annotation back to summary

private abstract Class ObjectIdGenerators.Base<T>

extends ObjectIdGenerator<T>
Class Inheritance
Known Direct Subclasses
com.fasterxml.jackson.annotation.ObjectIdGenerators.PropertyGenerator, com.fasterxml.jackson.annotation.ObjectIdGenerators.IntSequenceGenerator, com.fasterxml.jackson.annotation.ObjectIdGenerators.UUIDGenerator, com.fasterxml.jackson.annotation.ObjectIdGenerators.StringIdGenerator
Annotations
@SuppressWarnings:serial

Shared base class for concrete implementations.

Field Summary

Modifier and TypeField and Description
protected final Class<?>

Constructor Summary

AccessConstructor and Description
protected
Base(Class<?> scope)

Method Summary

Modifier and TypeMethod and Description
public boolean
canUseFor(ObjectIdGenerator<?> gen)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.canUseFor.

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 newForSerialization).
public abstract T
generateId(Object
POJO for which identifier is needed
forPojo
)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.generateId.

Method used for generating a new Object Identifier to serialize for given POJO.
public final Class<?>
Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerator:
forScopeisValidReferencePropertyNamekeymaySerializeAsObjectnewForSerialization

Field Detail

_scopeback to summary
protected final Class<?> _scope

Constructor Detail

Baseback to summary
protected Base(Class<?> scope)

Method Detail

canUseForback to summary
public boolean canUseFor(ObjectIdGenerator<?> gen)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.canUseFor.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.canUseFor.

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 newForSerialization).

Returns:boolean

True if this instance can be used as-is; false if not

Annotations
@Override
generateIdback to summary
public abstract T generateId(Object forPojo)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.generateId.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.generateId.

Method used for generating a new Object Identifier to serialize for given POJO.

Parameters
forPojo:Object

POJO for which identifier is needed

Returns:T

Object Identifier to use.

Annotations
@Override
getScopeback to summary
public final Class<?> getScope()

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.getScope.

Annotations
@Override
com.fasterxml.jackson.annotation back to summary

public final Class ObjectIdGenerators.IntSequenceGenerator

extends ObjectIdGenerators.Base<Integer>
Class Inheritance

Simple sequence-number based generator, which uses basic Java ints (starting with value 1) as Object Identifiers.

Field Summary

Modifier and TypeField and Description
protected transient int
private static final long
Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerators.Base:
_scope

Constructor Summary

AccessConstructor and Description
public
public
IntSequenceGenerator(Class<?> scope, int fv)

Method Summary

Modifier and TypeMethod and Description
public ObjectIdGenerator<Integer>
forScope(Class<?> scope)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.forScope.

Factory method to create a blueprint instance for specified scope.
public Integer
generateId(Object
POJO for which identifier is needed
forPojo
)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.generateId.

Method used for generating a new Object Identifier to serialize for given POJO.
protected int
public ObjectIdGenerator.IdKey
key(Object key)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Method for constructing key to use for ObjectId-to-POJO maps.
public ObjectIdGenerator<Integer>
newForSerialization(Object
Serialization context object used (of type com.fasterxml.jackson.databind.SerializerProvider); may be needed by more complex generators to access contextual information such as configuration.
context
)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce).
Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerators.Base:
canUseForgetScope

Field Detail

_nextValueback to summary
protected transient int _nextValue
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

IntSequenceGeneratorback to summary
public IntSequenceGenerator()
IntSequenceGeneratorback to summary
public IntSequenceGenerator(Class<?> scope, int fv)

Method Detail

forScopeback to summary
public ObjectIdGenerator<Integer> forScope(Class<?> scope)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.forScope.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.forScope.

Factory method to create a blueprint instance for specified scope. Generators that do not use scope may return 'this'.

Annotations
@Override
generateIdback to summary
public Integer generateId(Object forPojo)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.generateId.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.generateId.

Method used for generating a new Object Identifier to serialize for given POJO.

Parameters
forPojo:Object

POJO for which identifier is needed

Returns:Integer

Object Identifier to use.

Annotations
@Override
initialValueback to summary
protected int initialValue()
keyback to summary
public ObjectIdGenerator.IdKey key(Object key)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Method for constructing key to use for ObjectId-to-POJO maps.

Annotations
@Override
newForSerializationback to summary
public ObjectIdGenerator<Integer> newForSerialization(Object context)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

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 com.fasterxml.jackson.databind.SerializerProvider, but can not be declared here as type itself (as well as call to this object) comes from databind package.

Parameters
context:Object

Serialization context object used (of type com.fasterxml.jackson.databind.SerializerProvider); may be needed by more complex generators to access contextual information such as configuration.

Annotations
@Override
com.fasterxml.jackson.annotation back to summary

public abstract Class ObjectIdGenerators.None

extends ObjectIdGenerator<Object>
Class Inheritance
Annotations
@SuppressWarnings:serial

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.

Constructor Summary

AccessConstructor and Description
public
None()

Method Summary

Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerator:
canUseForforScopegenerateIdgetScopeisValidReferencePropertyNamekeymaySerializeAsObjectnewForSerialization

Constructor Detail

Noneback to summary
public None()
com.fasterxml.jackson.annotation back to summary

public abstract Class ObjectIdGenerators.PropertyGenerator

extends ObjectIdGenerators.Base<Object>
Class Inheritance

Abstract place-holder class which is used to denote case where Object Identifier to use comes from a POJO property (getter method or field). If so, value is written directly during serialization, and used as-is during deserialization.

Actual implementation class is part of databind package.

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerators.Base:
_scope

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerators.Base:
canUseForgenerateIdgetScope

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

PropertyGeneratorback to summary
protected PropertyGenerator(Class<?> scope)
com.fasterxml.jackson.annotation back to summary

public final Class ObjectIdGenerators.StringIdGenerator

extends ObjectIdGenerators.Base<String>
Class Inheritance

Implementation that will accept arbitrary (but unique) String Ids on deserialization, and (by default) use random UUID generation similar to 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.

Since
2.7

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerators.Base:
_scope

Constructor Summary

AccessConstructor and Description
public
private

Method Summary

Modifier and TypeMethod and Description
public boolean
canUseFor(ObjectIdGenerator<?> gen)

Overrides com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.canUseFor.

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 newForSerialization).
public ObjectIdGenerator<String>
forScope(Class<?> scope)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.forScope.

Factory method to create a blueprint instance for specified scope.
public String
generateId(Object
POJO for which identifier is needed
forPojo
)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.generateId.

Method used for generating a new Object Identifier to serialize for given POJO.
public ObjectIdGenerator.IdKey
key(Object key)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Method for constructing key to use for ObjectId-to-POJO maps.
public ObjectIdGenerator<String>
newForSerialization(Object
Serialization context object used (of type com.fasterxml.jackson.databind.SerializerProvider); may be needed by more complex generators to access contextual information such as configuration.
context
)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce).
Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerators.Base:
getScope

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

StringIdGeneratorback to summary
public StringIdGenerator()
StringIdGeneratorback to summary
private StringIdGenerator(Class<?> scope)

Method Detail

canUseForback to summary
public boolean canUseFor(ObjectIdGenerator<?> gen)

Overrides com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.canUseFor.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.canUseFor.

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 newForSerialization).

Returns:boolean

True if this instance can be used as-is; false if not

Annotations
@Override
forScopeback to summary
public ObjectIdGenerator<String> forScope(Class<?> scope)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.forScope.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.forScope.

Factory method to create a blueprint instance for specified scope. Generators that do not use scope may return 'this'.

Annotations
@Override
generateIdback to summary
public String generateId(Object forPojo)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.generateId.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.generateId.

Method used for generating a new Object Identifier to serialize for given POJO.

Parameters
forPojo:Object

POJO for which identifier is needed

Returns:String

Object Identifier to use.

Annotations
@Override
keyback to summary
public ObjectIdGenerator.IdKey key(Object key)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Method for constructing key to use for ObjectId-to-POJO maps.

Annotations
@Override
newForSerializationback to summary
public ObjectIdGenerator<String> newForSerialization(Object context)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

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 com.fasterxml.jackson.databind.SerializerProvider, but can not be declared here as type itself (as well as call to this object) comes from databind package.

Parameters
context:Object

Serialization context object used (of type com.fasterxml.jackson.databind.SerializerProvider); may be needed by more complex generators to access contextual information such as configuration.

Annotations
@Override
com.fasterxml.jackson.annotation back to summary

public final Class ObjectIdGenerators.UUIDGenerator

extends ObjectIdGenerators.Base<UUID>
Class Inheritance

Implementation that just uses java.util.UUIDs 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.

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerators.Base:
_scope

Constructor Summary

AccessConstructor and Description
public
private
UUIDGenerator(Class<?> scope)

Method Summary

Modifier and TypeMethod and Description
public boolean
canUseFor(ObjectIdGenerator<?> gen)

Overrides com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.canUseFor.

Since UUIDs are always unique, let's fully ignore scope definition
public ObjectIdGenerator<UUID>
forScope(Class<?> scope)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.forScope.

Can just return base instance since this is essentially scopeless
public UUID
generateId(Object
POJO for which identifier is needed
forPojo
)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.generateId.

Method used for generating a new Object Identifier to serialize for given POJO.
public ObjectIdGenerator.IdKey
key(Object key)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Method for constructing key to use for ObjectId-to-POJO maps.
public ObjectIdGenerator<UUID>
newForSerialization(Object
Serialization context object used (of type com.fasterxml.jackson.databind.SerializerProvider); may be needed by more complex generators to access contextual information such as configuration.
context
)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

Can just return base instance since this is essentially scopeless
Inherited from com.fasterxml.jackson.annotation.ObjectIdGenerators.Base:
getScope

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

UUIDGeneratorback to summary
public UUIDGenerator()
UUIDGeneratorback to summary
private UUIDGenerator(Class<?> scope)

Method Detail

canUseForback to summary
public boolean canUseFor(ObjectIdGenerator<?> gen)

Overrides com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.canUseFor.

Since UUIDs are always unique, let's fully ignore scope definition

Returns:boolean

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.canUseFor.

True if this instance can be used as-is; false if not

Annotations
@Override
forScopeback to summary
public ObjectIdGenerator<UUID> forScope(Class<?> scope)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.forScope.

Can just return base instance since this is essentially scopeless

Annotations
@Override
generateIdback to summary
public UUID generateId(Object forPojo)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerators.Base.generateId.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.generateId.

Method used for generating a new Object Identifier to serialize for given POJO.

Parameters
forPojo:Object

POJO for which identifier is needed

Returns:UUID

Object Identifier to use.

Annotations
@Override
keyback to summary
public ObjectIdGenerator.IdKey key(Object key)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.key.

Method for constructing key to use for ObjectId-to-POJO maps.

Annotations
@Override
newForSerializationback to summary
public ObjectIdGenerator<UUID> newForSerialization(Object context)

Implements abstract com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

Can just return base instance since this is essentially scopeless

Parameters
context:Object

Doc from com.fasterxml.jackson.annotation.ObjectIdGenerator.newForSerialization.

Serialization context object used (of type com.fasterxml.jackson.databind.SerializerProvider); may be needed by more complex generators to access contextual information such as configuration.

Annotations
@Override