Class AbstractKeyDeserializer<E extends AbstractPersistable>

java.lang.Object
com.fasterxml.jackson.databind.KeyDeserializer
ai.timefold.solver.examples.common.persistence.jackson.AbstractKeyDeserializer<E>
Type Parameters:
E - The type must have a JsonIdentityInfo annotation with JacksonUniqueIdGenerator as its generator.

public abstract class AbstractKeyDeserializer<E extends AbstractPersistable> extends com.fasterxml.jackson.databind.KeyDeserializer
Deserializes map key defined by JacksonUniqueIdGenerator to a child of AbstractPersistable.

Deserialization will create new instances of the map key type. Duplicate instances will be created if any other part of the JSON is also referencing the same type. In that case, a custom implementation of AbstractJsonSolutionFileIO must be used later to resolve the duplicates by comparing IDs of such objects and making sure only one instance exists with each ID.

Example: let us consider a "Location" object that has a field of type Map<Location, Distance>. When the outer Location object gets deserialized from List<Location>, the nested map needs to be deserialized as well. However, at this point, the Location objects used as keys in the map do not yet exist. (The rest of the list has not been read yet.) Therefore the deserializer needs to create a temporary dummy Location object to use as the map key. This object later needs to be replaced by the actual Location object by the AbstractJsonSolutionFileIO.

  • Nested Class Summary

    Nested classes/interfaces inherited from class com.fasterxml.jackson.databind.KeyDeserializer

    com.fasterxml.jackson.databind.KeyDeserializer.None
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractKeyDeserializer(Class<E> persistableClass)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract E
    createInstance(long id)
     
    final E
    deserializeKey(String value, com.fasterxml.jackson.databind.DeserializationContext deserializationContext)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractKeyDeserializer

      protected AbstractKeyDeserializer(Class<E> persistableClass)
  • Method Details

    • deserializeKey

      public final E deserializeKey(String value, com.fasterxml.jackson.databind.DeserializationContext deserializationContext)
      Specified by:
      deserializeKey in class com.fasterxml.jackson.databind.KeyDeserializer
    • createInstance

      protected abstract E createInstance(long id)