Interface ModelMapperSerializer

All Known Implementing Classes:
DefaultModelMapperSerializer

public interface ModelMapperSerializer
Handle serialization duties for ModelMapper instances using Kryo.
Author:
Jeff Fischer
  • Method Summary

    Modifier and Type
    Method
    Description
    org.modelmapper.ModelMapper
    deserialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, byte[] serialized)
    Given a byte array representation of a ModelMapper instance, deserialize into a concrete instance using Kryo.
    void
    A rich lifecycle method, calls will generate ModelMapper instances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitled mappers.zip.
    void
    generateCacheResources(Class<?>[] entities, boolean hashShapes)
    A rich lifecycle method, calls will generate ModelMapper instances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitled mappers.zip.
    hash(Class<?> entity)
    Create a hash uniquely identifying the class structure, including fields and types in the object graph.
    void
    loadCacheResources(Class<?>[] entities)
    A rich lifecycle method, calls will read ModelMapper serialized files from mappers.zip for the specified entities, deserialize those ModelMappers, and inject those mappers into cache upon application startup.
    byte[]
    serialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, org.modelmapper.ModelMapper mapper)
    Serialize the ModelMapper instance to a byte array - presumably to save to a file.
    com.esotericsoftware.kryo.kryo5.Kryo
    setup(Class<?>[] entities)
    Create a Kryo instance and perform the initial setup.
  • Method Details

    • setup

      com.esotericsoftware.kryo.kryo5.Kryo setup(Class<?>[] entities)
      Create a Kryo instance and perform the initial setup. See KryoCustomizer.
      Parameters:
      entities - The list of entities registered in the ORM.
      Returns:
      The configured Kryo instance.
    • serialize

      byte[] serialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, org.modelmapper.ModelMapper mapper)
      Serialize the ModelMapper instance to a byte array - presumably to save to a file.
      Parameters:
      kryo - The Kryo instance to use for serialization
      mapper - The ModelMapper instance to serialize
      Returns:
      The resulting byte array representing the serialized ModelMapper instance
    • deserialize

      org.modelmapper.ModelMapper deserialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, byte[] serialized)
      Given a byte array representation of a ModelMapper instance, deserialize into a concrete instance using Kryo.
      Parameters:
      kryo - The Kryo instance to use for deserialization
      serialized - The serialized model mapper
      Returns:
      The resulting ModelMapper instance after deserialization
    • hash

      String hash(Class<?> entity)
      Create a hash uniquely identifying the class structure, including fields and types in the object graph.
      Parameters:
      entity - The entity class to evaluate
      Returns:
      The hash uniquely identifying the current structure of the entity class
    • generateCacheResources

      void generateCacheResources(Class<?>[] entities)
      A rich lifecycle method, calls will generate ModelMapper instances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitled mappers.zip. The file is usually saved in the current application's source under the maven resources/cache directory structure. See ResourceProvider, and concrete implementations, for where and how the mappers.zip file is stored.

      A file called classes.zip is also created in the same location to hold any additional required classes that are needed to successfully deserialize the ModelMapper instances. These classes are generally injected into the target classloader upon deserialization (see loadCacheResources(Class[])).
      Parameters:
      entities - The entities from which to derive ModelMapper instances for serialization
    • generateCacheResources

      void generateCacheResources(Class<?>[] entities, boolean hashShapes)
      A rich lifecycle method, calls will generate ModelMapper instances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitled mappers.zip. The file is usually saved in the current application's source under the maven resources/cache directory structure. See ResourceProvider, and concrete implementations, for where and how the mappers.zip file is stored.

      A file called classes.zip is also created in the same location to hold any additional required classes that are needed to successfully deserialize the ModelMapper instances. These classes are generally injected into the target classloader upon deserialization (see loadCacheResources(Class[])).
      Parameters:
      entities - The entities from which to derive ModelMapper instances for serialization
      hashShapes - Whether or not the mapper cache should include a deep hash of the entity shape. This is useful if the cache archive is separated from the build process and can become stale. Stale cache entries will not match the entity shape at runtime and will not be accidentally included. This value should be false if the cache is always built during project compilation.
    • loadCacheResources

      void loadCacheResources(Class<?>[] entities)
      A rich lifecycle method, calls will read ModelMapper serialized files from mappers.zip for the specified entities, deserialize those ModelMappers, and inject those mappers into cache upon application startup. classes.zip is also consulted and classes discovered there are injected into the current classloader prior to attempting deserialization. See generateCacheResources(Class[]) for information on how mappers.zip and classes.zip originate.
      Parameters:
      entities - The entities from which to deserialize ModelMapper instances and populate cache