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 Details

  • Constructor Details

    • StateSerdes

      public StateSerdes(String topic, Serde<K> keySerde, 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 Serde<K> keySerde()
      Return the key serde.
      Returns:
      the key serde
    • valueSerde

      public Serde<V> valueSerde()
      Return the value serde.
      Returns:
      the value serde
    • keyDeserializer

      public Deserializer<K> keyDeserializer()
      Return the key deserializer.
      Returns:
      the key deserializer
    • keySerializer

      public Serializer<K> keySerializer()
      Return the key serializer.
      Returns:
      the key serializer
    • valueDeserializer

      public Deserializer<V> valueDeserializer()
      Return the value deserializer.
      Returns:
      the value deserializer
    • valueSerializer

      public 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