Class StateSerdes<K,V>

java.lang.Object
org.apache.kafka.streams.state.StateSerdes<K,V>
Type Parameters:
K - key type of serde
V - value type of serde

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

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    StateSerdes(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

    Modifier and Type
    Method
    Description
    org.apache.kafka.common.serialization.Deserializer<K>
    Return the key deserializer.
    keyFrom(byte[] rawKey)
    Deserialize the key from raw bytes.
    org.apache.kafka.common.serialization.Serde<K>
    Return the key serde.
    org.apache.kafka.common.serialization.Serializer<K>
    Return the key serializer.
    byte[]
    rawKey(K key)
    Serialize the given key.
    byte[]
    rawValue(V value)
    Serialize the given value.
    Return the topic.
    org.apache.kafka.common.serialization.Deserializer<V>
    Return the value deserializer.
    valueFrom(byte[] rawValue)
    Deserialize the value from raw bytes.
    org.apache.kafka.common.serialization.Serde<V>
    Return the value serde.
    org.apache.kafka.common.serialization.Serializer<V>
    Return the value serializer.
    static <K, V> StateSerdes<K,V>
    withBuiltinTypes(String topic, Class<K> keyClass, 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

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • StateSerdes

      public StateSerdes(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:
      IllegalArgumentException - if key or value serde is null
  • Method Details

    • withBuiltinTypes

      public static <K, V> StateSerdes<K,V> withBuiltinTypes(String topic, Class<K> keyClass, 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 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