Class JacksonUniqueIdGenerator
- All Implemented Interfaces:
Serializable
- Serializing maps where keys are themselves serialized objects that need to be referenced later.
- Serializing polymorphic types.
- Serializing self-referential and/or recursive types.
This class and other classes in this package aim to solve those issues
by introducing a new ID field on all serialized objects,
typically called "@id".
This field is used exclusively for referencing objects in the serialized JSON,
it never enters the Java data model.
Therefore it is not related to AbstractPersistable.getId(),
which is the actual object ID used in the Java examples.
See Vehicle Routing example to learn how to use this pattern.
For use cases without these advanced needs,
the less complex way of using JsonIdentityInfo with ObjectIdGenerators.PropertyGenerator is preferred.
See Cloud Balancing example to learn how to use this pattern.
The implementation is similar in principle to ObjectIdGenerators.UUIDGenerator, but without the long and undescriptive UUIDs.
Works only for children of AbstractPersistable.
No two such classes must have the same Class.getSimpleName().
-
Nested Class Summary
Nested classes/interfaces inherited from class com.fasterxml.jackson.annotation.ObjectIdGenerator
com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanUseFor(com.fasterxml.jackson.annotation.ObjectIdGenerator<?> gen) com.fasterxml.jackson.annotation.ObjectIdGenerator<String>generateId(Object forPojo) Class<?>getScope()com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKeycom.fasterxml.jackson.annotation.ObjectIdGenerator<String>newForSerialization(Object context) Methods inherited from class com.fasterxml.jackson.annotation.ObjectIdGenerator
isValidReferencePropertyName, maySerializeAsObject
-
Constructor Details
-
JacksonUniqueIdGenerator
public JacksonUniqueIdGenerator()
-
-
Method Details
-
getScope
- Specified by:
getScopein classcom.fasterxml.jackson.annotation.ObjectIdGenerator<String>
-
canUseFor
public boolean canUseFor(com.fasterxml.jackson.annotation.ObjectIdGenerator<?> gen) - Specified by:
canUseForin classcom.fasterxml.jackson.annotation.ObjectIdGenerator<String>
-
forScope
- Specified by:
forScopein classcom.fasterxml.jackson.annotation.ObjectIdGenerator<String>
-
newForSerialization
public com.fasterxml.jackson.annotation.ObjectIdGenerator<String> newForSerialization(Object context) - Specified by:
newForSerializationin classcom.fasterxml.jackson.annotation.ObjectIdGenerator<String>
-
key
- Specified by:
keyin classcom.fasterxml.jackson.annotation.ObjectIdGenerator<String>
-
generateId
- Specified by:
generateIdin classcom.fasterxml.jackson.annotation.ObjectIdGenerator<String>
-