Class JacksonUniqueIdGenerator
- java.lang.Object
-
- com.fasterxml.jackson.annotation.ObjectIdGenerator<String>
-
- org.optaplanner.examples.common.persistence.jackson.JacksonUniqueIdGenerator
-
- All Implemented Interfaces:
Serializable
public final class JacksonUniqueIdGenerator extends com.fasterxml.jackson.annotation.ObjectIdGenerator<String>
Exists so that complex data models (such as TSP chaining) can be serialized/deserialized. These complexities include:- 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
JsonIdentityInfowithObjectIdGenerators.PropertyGeneratoris 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 ofAbstractPersistable. No two such classes must have the sameClass.getSimpleName().
-
-
Constructor Summary
Constructors Constructor Description JacksonUniqueIdGenerator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanUseFor(com.fasterxml.jackson.annotation.ObjectIdGenerator<?> gen)com.fasterxml.jackson.annotation.ObjectIdGenerator<String>forScope(Class<?> scope)StringgenerateId(Object forPojo)Class<?>getScope()com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKeykey(Object key)com.fasterxml.jackson.annotation.ObjectIdGenerator<String>newForSerialization(Object context)
-
-
-
Method Detail
-
getScope
public Class<?> 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
public com.fasterxml.jackson.annotation.ObjectIdGenerator<String> forScope(Class<?> scope)
- 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
public com.fasterxml.jackson.annotation.ObjectIdGenerator.IdKey key(Object key)
- Specified by:
keyin classcom.fasterxml.jackson.annotation.ObjectIdGenerator<String>
-
-