Interface ModelMapperSerializer
-
- All Known Implementing Classes:
DefaultModelMapperSerializer
public interface ModelMapperSerializerHandle serialization duties forModelMapperinstances usingKryo.- Author:
- Jeff Fischer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description org.modelmapper.ModelMapperdeserialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, byte[] serialized)Given a byte array representation of aModelMapperinstance, deserialize into a concrete instance usingKryo.voidgenerateCacheResources(Class<?>[] entities)A rich lifecycle method, calls will generateModelMapperinstances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip.voidgenerateCacheResources(Class<?>[] entities, boolean hashShapes)A rich lifecycle method, calls will generateModelMapperinstances for the specified entities, serialize those ModelMappers, and persist those mappers to disk in a file entitledmappers.zip.Stringhash(Class<?> entity)Create a hash uniquely identifying the class structure, including fields and types in the object graph.voidloadCacheResources(Class<?>[] entities)A rich lifecycle method, calls will readModelMapperserialized files frommappers.zipfor 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 theModelMapperinstance to a byte array - presumably to save to a file.com.esotericsoftware.kryo.kryo5.Kryosetup(Class<?>[] entities)Create aKryoinstance and perform the initial setup.
-
-
-
Method Detail
-
setup
com.esotericsoftware.kryo.kryo5.Kryo setup(Class<?>[] entities)
Create aKryoinstance and perform the initial setup. SeeKryoCustomizer.- Parameters:
entities- The list of entities registered in the ORM.- Returns:
- The configured
Kryoinstance.
-
serialize
byte[] serialize(com.esotericsoftware.kryo.kryo5.Kryo kryo, org.modelmapper.ModelMapper mapper)Serialize theModelMapperinstance to a byte array - presumably to save to a file.- Parameters:
kryo- TheKryoinstance to use for serializationmapper- TheModelMapperinstance 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 aModelMapperinstance, deserialize into a concrete instance usingKryo.- Parameters:
kryo- TheKryoinstance to use for deserializationserialized- 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 generateModelMapperinstances 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.
A file calledclasses.zipis 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
void generateCacheResources(Class<?>[] entities, boolean hashShapes)
A rich lifecycle method, calls will generateModelMapperinstances 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.
A file calledclasses.zipis 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
void loadCacheResources(Class<?>[] entities)
A rich lifecycle method, calls will readModelMapperserialized files frommappers.zipfor the specified entities, deserialize those ModelMappers, and inject those mappers into cache upon application startup.classes.zipis 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
-
-