public class DefaultStringKeySerializer extends Object implements ObjectSerializer
The default key serializer used by caches that require serializing the keys as strings. Builds a key from the
configured cache name and String conversion of the object as dictated by ConversionService
.
Note this implementation does not support deserialization
JDK
Constructor and Description |
---|
DefaultStringKeySerializer(String cacheName,
Charset charset,
ConversionService<?> conversionService)
Construct a default serializer for given parameters.
|
Modifier and Type | Method and Description |
---|---|
<T> Optional<T> |
deserialize(InputStream inputStream,
Class<T> requiredType)
Deserialize the given object to bytes.
|
Optional<byte[]> |
serialize(Object object)
Serialize the given object to a byte[].
|
void |
serialize(Object object,
OutputStream outputStream)
Serialize the given object to a byte[].
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
deserialize, deserialize
public DefaultStringKeySerializer(String cacheName, Charset charset, ConversionService<?> conversionService)
cacheName
- The cache key or namecharset
- The charset used for serialization and de-serializing instance from the to/from cacheconversionService
- To convert value/object from the cache to Stringpublic Optional<byte[]> serialize(Object object) throws SerializationException
ObjectSerializer
serialize
in interface ObjectSerializer
object
- The object to serializeSerializationException
- if there is a serialization problempublic void serialize(Object object, OutputStream outputStream) throws SerializationException
ObjectSerializer
serialize
in interface ObjectSerializer
object
- The object to serializeoutputStream
- The output streamSerializationException
- if there is a serialization problempublic <T> Optional<T> deserialize(InputStream inputStream, Class<T> requiredType) throws SerializationException
ObjectSerializer
deserialize
in interface ObjectSerializer
T
- The required generic typeinputStream
- The input streamrequiredType
- The required typeOptional
of the objectSerializationException
- if there is a serialization problem