Package org.apache.kafka.streams.state
Class StateSerdes<K,V>
java.lang.Object
org.apache.kafka.streams.state.StateSerdes<K,V>
- Type Parameters:
K
- key type of serdeV
- value type of serde
public final class StateSerdes<K,V> extends Object
Factory for creating serializers / deserializers for state stores in Kafka Streams.
-
Constructor Summary
Constructors Constructor Description 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. -
Method Summary
Modifier and Type Method Description Deserializer<K>
keyDeserializer()
Return the key deserializer.K
keyFrom(byte[] rawKey)
Deserialize the key from raw bytes.Serde<K>
keySerde()
Return the key serde.Serializer<K>
keySerializer()
Return the key serializer.byte[]
rawKey(K key)
Serialize the given key.byte[]
rawValue(V value)
Serialize the given value.String
topic()
Return the topic.Deserializer<V>
valueDeserializer()
Return the value deserializer.V
valueFrom(byte[] rawValue)
Deserialize the value from raw bytes.Serde<V>
valueSerde()
Return the value serde.Serializer<V>
valueSerializer()
Return the value serializer.static <K, V> StateSerdes<K,V>
withBuiltinTypes(String topic, Class<K> keyClass, Class<V> valueClass)
Create a new instance ofStateSerdes
for the given state name and key-/value-type classes.
-
Constructor Details
-
StateSerdes
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 namekeySerde
- the serde for keys; cannot be nullvalueSerde
- 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 ofStateSerdes
for the given state name and key-/value-type classes.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
topic
- the topic namekeyClass
- the class of the key typevalueClass
- the class of the value type- Returns:
- a new instance of
StateSerdes
-
keySerde
Return the key serde.- Returns:
- the key serde
-
valueSerde
Return the value serde.- Returns:
- the value serde
-
keyDeserializer
Return the key deserializer.- Returns:
- the key deserializer
-
keySerializer
Return the key serializer.- Returns:
- the key serializer
-
valueDeserializer
Return the value deserializer.- Returns:
- the value deserializer
-
valueSerializer
Return the value serializer.- Returns:
- the value serializer
-
topic
Return the topic.- Returns:
- the topic
-
keyFrom
Deserialize the key from raw bytes.- Parameters:
rawKey
- the key as raw bytes- Returns:
- the key as typed object
-
valueFrom
Deserialize the value from raw bytes.- Parameters:
rawValue
- the value as raw bytes- Returns:
- the value as typed object
-
rawKey
Serialize the given key.- Parameters:
key
- the key to be serialized- Returns:
- the serialized key
-
rawValue
Serialize the given value.- Parameters:
value
- the value to be serialized- Returns:
- the serialized value
-