Package com.fasterxml.jackson.annotation
Class ObjectIdGenerators.StringIdGenerator
- java.lang.Object
-
- com.fasterxml.jackson.annotation.ObjectIdGenerator<T>
-
- com.fasterxml.jackson.annotation.ObjectIdGenerators.StringIdGenerator
-
- All Implemented Interfaces:
java.io.Serializable
- Enclosing class:
- ObjectIdGenerators
public static final class ObjectIdGenerators.StringIdGenerator extends ObjectIdGenerator<T>
Implementation that will accept arbitrary (but unique) String Ids on deserialization, and (by default) use random UUID generation similar toObjectIdGenerators.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,
ObjectIdGenerators.UUIDGenerator
is a better match as it will also validate ids being used.- Since:
- 2.7
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.fasterxml.jackson.annotation.ObjectIdGenerator
ObjectIdGenerator.IdKey
-
-
Constructor Summary
Constructors Constructor Description StringIdGenerator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canUseFor(ObjectIdGenerator<?> gen)
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 (usingObjectIdGenerator.newForSerialization(java.lang.Object)
).ObjectIdGenerator<java.lang.String>
forScope(java.lang.Class<?> scope)
Factory method to create a blueprint instance for specified scope.java.lang.String
generateId(java.lang.Object forPojo)
Method used for generating a new Object Identifier to serialize for given POJO.ObjectIdGenerator.IdKey
key(java.lang.Object key)
Method for constructing key to use for ObjectId-to-POJO maps.ObjectIdGenerator<java.lang.String>
newForSerialization(java.lang.Object context)
Factory method called to create a new instance to use for serialization: needed since generators may have state (next id to produce).-
Methods inherited from class com.fasterxml.jackson.annotation.ObjectIdGenerator
isValidReferencePropertyName, maySerializeAsObject
-
-
-
-
Method Detail
-
forScope
public ObjectIdGenerator<java.lang.String> forScope(java.lang.Class<?> scope)
Description copied from class:ObjectIdGenerator
Factory method to create a blueprint instance for specified scope. Generators that do not use scope may return 'this'.- Specified by:
forScope
in classObjectIdGenerator<java.lang.String>
-
newForSerialization
public ObjectIdGenerator<java.lang.String> newForSerialization(java.lang.Object context)
Description copied from class:ObjectIdGenerator
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.- Specified by:
newForSerialization
in classObjectIdGenerator<java.lang.String>
- Parameters:
context
- Serialization context object used (of typecom.fasterxml.jackson.databind.SerializerProvider
; may be needed by more complex generators to access contextual information such as configuration.
-
generateId
public java.lang.String generateId(java.lang.Object forPojo)
Description copied from class:ObjectIdGenerator
Method used for generating a new Object Identifier to serialize for given POJO.- Parameters:
forPojo
- POJO for which identifier is needed- Returns:
- Object Identifier to use.
-
key
public ObjectIdGenerator.IdKey key(java.lang.Object key)
Description copied from class:ObjectIdGenerator
Method for constructing key to use for ObjectId-to-POJO maps.- Specified by:
key
in classObjectIdGenerator<java.lang.String>
-
canUseFor
public boolean canUseFor(ObjectIdGenerator<?> gen)
Description copied from class:ObjectIdGenerator
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 (usingObjectIdGenerator.newForSerialization(java.lang.Object)
).- Returns:
- True if this instance can be used as-is; false if not
-
-