Package org.apache.kafka.connect.storage
Class StringConverter
- java.lang.Object
-
- org.apache.kafka.connect.storage.StringConverter
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Configurable,Converter,HeaderConverter
public class StringConverter extends Object implements Converter, HeaderConverter
ConverterandHeaderConverterimplementation that only supports serializing to strings. When converting Kafka Connect data to bytes, the schema will be ignored andObject.toString()will always be invoked to convert the data to a String. When converting from bytes to Kafka Connect format, the converter will only ever return an optional string schema and a string or null. Encoding configuration is identical toStringSerializerandStringDeserializer, but for convenience this class can also be configured to use the same encoding for both encoding and decoding with theconverter.encodingsetting. This implementation currently does nothing with the topic names or header names.
-
-
Constructor Summary
Constructors Constructor Description StringConverter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()ConfigDefconfig()Configuration specification for this set of header converters.voidconfigure(Map<String,?> configs)Configure this class with the given key-value pairsvoidconfigure(Map<String,?> configs, boolean isKey)Configure this class.byte[]fromConnectData(String topic, Schema schema, Object value)Convert a Kafka Connect data object to a native object for serialization.byte[]fromConnectHeader(String topic, String headerKey, Schema schema, Object value)SchemaAndValuetoConnectData(String topic, byte[] value)Convert a native object to a Kafka Connect data object.SchemaAndValuetoConnectHeader(String topic, String headerKey, byte[] value)Convert the header name and byte array value into aHeaderobject.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.kafka.connect.storage.Converter
fromConnectData, toConnectData
-
-
-
-
Method Detail
-
config
public ConfigDef config()
Description copied from interface:HeaderConverterConfiguration specification for this set of header converters.- Specified by:
configin interfaceHeaderConverter- Returns:
- the configuration specification; may not be null
-
configure
public void configure(Map<String,?> configs)
Description copied from interface:ConfigurableConfigure this class with the given key-value pairs- Specified by:
configurein interfaceConfigurable
-
configure
public void configure(Map<String,?> configs, boolean isKey)
Description copied from interface:ConverterConfigure this class.
-
fromConnectData
public byte[] fromConnectData(String topic, Schema schema, Object value)
Description copied from interface:ConverterConvert a Kafka Connect data object to a native object for serialization.- Specified by:
fromConnectDatain interfaceConverter- Parameters:
topic- the topic associated with the dataschema- the schema for the valuevalue- the value to convert- Returns:
- the serialized value
-
toConnectData
public SchemaAndValue toConnectData(String topic, byte[] value)
Description copied from interface:ConverterConvert a native object to a Kafka Connect data object.- Specified by:
toConnectDatain interfaceConverter- Parameters:
topic- the topic associated with the datavalue- the value to convert- Returns:
- an object containing the
Schemaand the converted value
-
fromConnectHeader
public byte[] fromConnectHeader(String topic, String headerKey, Schema schema, Object value)
Description copied from interface:HeaderConverter- Specified by:
fromConnectHeaderin interfaceHeaderConverter- Parameters:
topic- the name of the topic for the record containing the headerheaderKey- the header's key; may not be nullschema- the schema for the header's value; may be nullvalue- the header's value to convert; may be null- Returns:
- the byte array form of the Header's value; may be null if the value is null
-
toConnectHeader
public SchemaAndValue toConnectHeader(String topic, String headerKey, byte[] value)
Description copied from interface:HeaderConverterConvert the header name and byte array value into aHeaderobject.- Specified by:
toConnectHeaderin interfaceHeaderConverter- Parameters:
topic- the name of the topic for the record containing the headerheaderKey- the header's key; may not be nullvalue- the header's raw value; may be null- Returns:
- the
SchemaAndValue; may not be null
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-