Class CollectionEnDec
java.lang.Object
io.aiven.kafka.connect.amqp.common.data.EncoderDecoder
io.aiven.kafka.connect.amqp.common.data.CollectionEnDec
Converts collections and maps with arbitrary values into Kafka
Struct types.
This Encodeer/Decoder should come after KafkaEnDec if it is used in order to allow the standard Kafka conversion to occur before the conversions here.
This Encoder/Decorder handles the following types and in the following order:
- Arbitrary
java.util.Collectionimplementation - converts to a Struct with fields names by the numeric index of the natural order of the collection. Values of the fields are encoded/decoded using the current EncoderDecoder instance. The struct itself is named as the class name of the collection implementation. - Arbitrary
java.util.Mapimplementation - converts to a struct where each field is named by thetoStringrepresentation of the key and the value is encoded/decoded using the current EncoderDecoder instance. The struct itself is named as the class name of the Map implementation. - Array of arbitrary objects - converts to a Struct with fields names by the numeric index of the array. Values of the array are encoded/decoded using the current EncoderDecoder instance. The struct itself is named as the class name of the array implementation.
-
Nested Class Summary
Nested classes/interfaces inherited from class io.aiven.kafka.connect.amqp.common.data.EncoderDecoder
EncoderDecoder.ChainedEnDec -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecode(org.apache.kafka.connect.data.SchemaAndValue schemaAndValue) Decodes a SchemaAndValue into an object.Optional<org.apache.kafka.connect.data.SchemaAndValue>Encodes thevalueas a SchemaAndValue.Optional<org.apache.kafka.connect.data.SchemaAndValue>encodeCollection(org.apache.kafka.connect.data.SchemaBuilder schemaBuilder, Collection<?> collection) Create a struct that contains the items from the collection.Methods inherited from class io.aiven.kafka.connect.amqp.common.data.EncoderDecoder
andThen, self, setSelf, toString
-
Constructor Details
-
CollectionEnDec
public CollectionEnDec()Constructor.
-
-
Method Details
-
encodeCollection
public Optional<org.apache.kafka.connect.data.SchemaAndValue> encodeCollection(org.apache.kafka.connect.data.SchemaBuilder schemaBuilder, Collection<?> collection) Create a struct that contains the items from the collection.- Parameters:
schemaBuilder- the schema builder to add the schema to.collection- the collection to process.- Returns:
- the completed schema.
-
encode
Description copied from class:EncoderDecoderEncodes thevalueas a SchemaAndValue. If this converter can not perform the encoding it returns an emptyOptional.- Specified by:
encodein classEncoderDecoder- Parameters:
value- the value to convert.- Returns:
- the Optional SchemaAndValue or an empty Optional.
-
decode
Description copied from class:EncoderDecoderDecodes a SchemaAndValue into an object. If this converter can not perform the decoding it returns an emptyOptional.- Specified by:
decodein classEncoderDecoder- Parameters:
schemaAndValue- the schema and value to decode.- Returns:
- the Optional Object or an empty Optional if not decoded.
-