E - type of the underlying object that the collection holdspublic class CollectionSerde<E> extends Object implements org.apache.kafka.common.serialization.Serde<Collection<E>>
Serde for Collection implementations.
Whenever a Kafka Stream application needs to collect data into a container object like
Collection, then this Serde class can be used as a convenience for
serialization needs. Some examples of where using this may handy is when the application
needs to do aggregation or reduction operations where it needs to simply hold an
Iterable type.
By default, this Serde will use JsonSerde for serializing the inner objects.
This can be changed by providing an explicit Serde during creation of this object.
Here is an example of a possible use case:
.aggregate(ArrayList::new,
(k, v, aggregates) -> {
aggregates.add(v);
return aggregates;
},
Materialized.<String, Collection<Foo>, WindowStore<Bytes, byte[]>>as(
"foo-store")
.withKeySerde(Serdes.String())
.withValueSerde(new CollectionSerde<>(Foo.class, ArrayList.class)))
*
Supported Collection types by this Serde are - ArrayList, LinkedList,
PriorityQueue and HashSet. Deserializer will throw an exception
if any other Collection types are used.| Constructor and Description |
|---|
CollectionSerde(Class<?> targetTypeForJsonSerde,
Class<?> collectionsClass)
Constructor to delegate serialization operations for the inner objects
to
JsonSerde. |
CollectionSerde(org.apache.kafka.common.serialization.Serde<E> serde,
Class<?> collectionsClass)
Constructor to use when the application wants to specify the type
of the Serde used for the inner object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
configure(Map<String,?> configs,
boolean isKey) |
org.apache.kafka.common.serialization.Deserializer<Collection<E>> |
deserializer() |
org.apache.kafka.common.serialization.Serializer<Collection<E>> |
serializer() |
public CollectionSerde(org.apache.kafka.common.serialization.Serde<E> serde, Class<?> collectionsClass)
serde - specify an explicit SerdecollectionsClass - type of the Collection classpublic CollectionSerde(Class<?> targetTypeForJsonSerde, Class<?> collectionsClass)
JsonSerde.targetTypeForJsonSerde - target type used by the JsonSerdecollectionsClass - type of the Collection classpublic org.apache.kafka.common.serialization.Serializer<Collection<E>> serializer()
serializer in interface org.apache.kafka.common.serialization.Serde<Collection<E>>public org.apache.kafka.common.serialization.Deserializer<Collection<E>> deserializer()
deserializer in interface org.apache.kafka.common.serialization.Serde<Collection<E>>public void configure(Map<String,?> configs, boolean isKey)
configure in interface org.apache.kafka.common.serialization.Serde<Collection<E>>public void close()
close in interface Closeableclose in interface AutoCloseableclose in interface org.apache.kafka.common.serialization.Serde<Collection<E>>Copyright © 2022 Pivotal Software, Inc.. All rights reserved.