Class StateSerdes<K,​V>

  • Type Parameters:
    K - key type of serde
    V - value type of serde

    public final class StateSerdes<K,​V>
    extends java.lang.Object
    Factory for creating serializers / deserializers for state stores in Kafka Streams.
    • Constructor Summary

      Constructors 
      Constructor Description
      StateSerdes​(java.lang.String topic, org.apache.kafka.common.serialization.Serde<K> keySerde, org.apache.kafka.common.serialization.Serde<V> valueSerde)
      Create a context for serialization using the specified serializers and deserializers which must match the key and value types used as parameters for this object; the state changelog topic is provided to bind this serde factory to, so that future calls for serialize / deserialize do not need to provide the topic name any more.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer()
      Return the key deserializer.
      K keyFrom​(byte[] rawKey)
      Deserialize the key from raw bytes.
      org.apache.kafka.common.serialization.Serde<K> keySerde()
      Return the key serde.
      org.apache.kafka.common.serialization.Serializer<K> keySerializer()
      Return the key serializer.
      byte[] rawKey​(K key)
      Serialize the given key.
      byte[] rawValue​(V value)
      Serialize the given value.
      java.lang.String topic()
      Return the topic.
      org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer()
      Return the value deserializer.
      V valueFrom​(byte[] rawValue)
      Deserialize the value from raw bytes.
      org.apache.kafka.common.serialization.Serde<V> valueSerde()
      Return the value serde.
      org.apache.kafka.common.serialization.Serializer<V> valueSerializer()
      Return the value serializer.
      static <K,​V>
      StateSerdes<K,​V>
      withBuiltinTypes​(java.lang.String topic, java.lang.Class<K> keyClass, java.lang.Class<V> valueClass)
      Create a new instance of StateSerdes for the given state name and key-/value-type classes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StateSerdes

        public StateSerdes​(java.lang.String topic,
                           org.apache.kafka.common.serialization.Serde<K> keySerde,
                           org.apache.kafka.common.serialization.Serde<V> valueSerde)
        Create a context for serialization using the specified serializers and deserializers which must match the key and value types used as parameters for this object; the state changelog topic is provided to bind this serde factory to, so that future calls for serialize / deserialize do not need to provide the topic name any more.
        Parameters:
        topic - the topic name
        keySerde - the serde for keys; cannot be null
        valueSerde - the serde for values; cannot be null
        Throws:
        java.lang.IllegalArgumentException - if key or value serde is null
    • Method Detail

      • withBuiltinTypes

        public static <K,​V> StateSerdes<K,​V> withBuiltinTypes​(java.lang.String topic,
                                                                          java.lang.Class<K> keyClass,
                                                                          java.lang.Class<V> valueClass)
        Create a new instance of StateSerdes for the given state name and key-/value-type classes.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        topic - the topic name
        keyClass - the class of the key type
        valueClass - the class of the value type
        Returns:
        a new instance of StateSerdes
      • keySerde

        public org.apache.kafka.common.serialization.Serde<K> keySerde()
        Return the key serde.
        Returns:
        the key serde
      • valueSerde

        public org.apache.kafka.common.serialization.Serde<V> valueSerde()
        Return the value serde.
        Returns:
        the value serde
      • keyDeserializer

        public org.apache.kafka.common.serialization.Deserializer<K> keyDeserializer()
        Return the key deserializer.
        Returns:
        the key deserializer
      • keySerializer

        public org.apache.kafka.common.serialization.Serializer<K> keySerializer()
        Return the key serializer.
        Returns:
        the key serializer
      • valueDeserializer

        public org.apache.kafka.common.serialization.Deserializer<V> valueDeserializer()
        Return the value deserializer.
        Returns:
        the value deserializer
      • valueSerializer

        public org.apache.kafka.common.serialization.Serializer<V> valueSerializer()
        Return the value serializer.
        Returns:
        the value serializer
      • topic

        public java.lang.String topic()
        Return the topic.
        Returns:
        the topic
      • keyFrom

        public K keyFrom​(byte[] rawKey)
        Deserialize the key from raw bytes.
        Parameters:
        rawKey - the key as raw bytes
        Returns:
        the key as typed object
      • valueFrom

        public V valueFrom​(byte[] rawValue)
        Deserialize the value from raw bytes.
        Parameters:
        rawValue - the value as raw bytes
        Returns:
        the value as typed object
      • rawKey

        public byte[] rawKey​(K key)
        Serialize the given key.
        Parameters:
        key - the key to be serialized
        Returns:
        the serialized key
      • rawValue

        public byte[] rawValue​(V value)
        Serialize the given value.
        Parameters:
        value - the value to be serialized
        Returns:
        the serialized value