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 TypeMethodDescriptionorg.modelmapper.ModelMapper
deserialize
(com.esotericsoftware.kryo.kryo5.Kryo kryo, byte[] serialized) Given a byte array representation of aModelMapper
instance, deserialize into a concrete instance usingKryo
.void
generateCacheResources
(Class<?>[] entities) A rich lifecycle method, calls will generateModelMapper
instances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip
.void
generateCacheResources
(Class<?>[] entities, boolean hashShapes) A rich lifecycle method, calls will generateModelMapper
instances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip
.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 readModelMapper
serialized files frommappers.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 theModelMapper
instance to a byte array - presumably to save to a file.com.esotericsoftware.kryo.kryo5.Kryo
Create aKryo
instance and perform the initial setup.
-
Method Details
-
setup
Create aKryo
instance and perform the initial setup. SeeKryoCustomizer
.- 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 theModelMapper
instance to a byte array - presumably to save to a file.- Parameters:
kryo
- TheKryo
instance to use for serializationmapper
- TheModelMapper
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 aModelMapper
instance, deserialize into a concrete instance usingKryo
.- Parameters:
kryo
- TheKryo
instance to use for deserializationserialized
- The serialized model mapper- Returns:
- The resulting ModelMapper instance after deserialization
-
hash
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
A rich lifecycle method, calls will generateModelMapper
instances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip
. The file is usually saved in the current application's source under the maven resources/cache directory structure. SeeResourceProvider
, and concrete implementations, for where and how the mappers.zip file is stored.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 (seeloadCacheResources(Class[])
).- Parameters:
entities
- The entities from which to derive ModelMapper instances for serialization
-
generateCacheResources
A rich lifecycle method, calls will generateModelMapper
instances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip
. The file is usually saved in the current application's source under the maven resources/cache directory structure. SeeResourceProvider
, and concrete implementations, for where and how the mappers.zip file is stored.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 (seeloadCacheResources(Class[])
).- Parameters:
entities
- The entities from which to derive ModelMapper instances for serializationhashShapes
- 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
A rich lifecycle method, calls will readModelMapper
serialized files frommappers.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. SeegenerateCacheResources(Class[])
for information on how mappers.zip and classes.zip originate.- Parameters:
entities
- The entities from which to deserialize ModelMapper instances and populate cache
-