Class JavaSerializationCopier
- java.lang.Object
-
- com.github.benmanes.caffeine.jcache.copy.AbstractCopier<byte[]>
-
- com.github.benmanes.caffeine.jcache.copy.JavaSerializationCopier
-
- All Implemented Interfaces:
Copier
public class JavaSerializationCopier extends AbstractCopier<byte[]>
A strategy that uses Java serialization if a fast path approach is not applicable.Beware that native serialization is slow and is provided for completeness. In practice, it is recommended that a higher performance alternative is used, which is provided by numerous external libraries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
JavaSerializationCopier.ClassLoaderAwareObjectInputStream
An ObjectInputStream that instantiates using the supplied classloader.
-
Constructor Summary
Constructors Constructor Description JavaSerializationCopier()
JavaSerializationCopier(java.util.Set<java.lang.Class<?>> immutableClasses, java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>> deepCopyStrategies)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Object
deserialize(byte[] data, java.lang.ClassLoader classLoader)
Deserializes the data using the provided classloader.protected byte[]
serialize(java.lang.Object object)
Serializes the object.-
Methods inherited from class com.github.benmanes.caffeine.jcache.copy.AbstractCopier
canDeeplyCopy, copy, isImmutable, javaDeepCopyStrategies, javaImmutableClasses, roundtrip
-
-
-
-
Constructor Detail
-
JavaSerializationCopier
public JavaSerializationCopier()
-
JavaSerializationCopier
public JavaSerializationCopier(java.util.Set<java.lang.Class<?>> immutableClasses, java.util.Map<java.lang.Class<?>,java.util.function.Function<java.lang.Object,java.lang.Object>> deepCopyStrategies)
-
-
Method Detail
-
serialize
protected byte[] serialize(java.lang.Object object)
Description copied from class:AbstractCopier
Serializes the object.- Specified by:
serialize
in classAbstractCopier<byte[]>
- Parameters:
object
- the object to serialize- Returns:
- the serialized bytes
-
deserialize
protected java.lang.Object deserialize(byte[] data, java.lang.ClassLoader classLoader)
Description copied from class:AbstractCopier
Deserializes the data using the provided classloader.- Specified by:
deserialize
in classAbstractCopier<byte[]>
- Parameters:
data
- the serialized bytesclassLoader
- the classloader to create the instance with- Returns:
- the deserialized object
-
-