Class DefaultStringKeySerializer

java.lang.Object
io.micronaut.cache.serialize.DefaultStringKeySerializer
All Implemented Interfaces:
io.micronaut.core.serialize.ObjectSerializer

public class DefaultStringKeySerializer extends Object implements io.micronaut.core.serialize.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

Since:
1.0
Author:
Graeme Rocher
  • Constructor Details

    • DefaultStringKeySerializer

      public DefaultStringKeySerializer(String cacheName, Charset charset, io.micronaut.core.convert.ConversionService conversionService)
      Construct a default serializer for given parameters.
      Parameters:
      cacheName - The cache key or name
      charset - The charset used for serialization and de-serializing instance from the to/from cache
      conversionService - To convert value/object from the cache to String
  • Method Details

    • serialize

      public Optional<byte[]> serialize(Object object) throws io.micronaut.core.serialize.exceptions.SerializationException
      Specified by:
      serialize in interface io.micronaut.core.serialize.ObjectSerializer
      Throws:
      io.micronaut.core.serialize.exceptions.SerializationException
    • serialize

      public void serialize(Object object, OutputStream outputStream) throws io.micronaut.core.serialize.exceptions.SerializationException
      Specified by:
      serialize in interface io.micronaut.core.serialize.ObjectSerializer
      Throws:
      io.micronaut.core.serialize.exceptions.SerializationException
    • deserialize

      public <T> Optional<T> deserialize(InputStream inputStream, Class<T> requiredType) throws io.micronaut.core.serialize.exceptions.SerializationException
      Specified by:
      deserialize in interface io.micronaut.core.serialize.ObjectSerializer
      Throws:
      io.micronaut.core.serialize.exceptions.SerializationException