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
Converter and HeaderConverter implementation that only supports serializing to strings. When converting Kafka Connect data to bytes, the schema will be ignored and Object.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 to StringSerializer and StringDeserializer, but for convenience this class can also be configured to use the same encoding for both encoding and decoding with the converter.encoding setting. This implementation currently does nothing with the topic names or header names.
  • Constructor Details

    • StringConverter

      public StringConverter()
  • Method Details

    • config

      public ConfigDef config()
      Description copied from interface: HeaderConverter
      Configuration specification for this set of header converters.
      Specified by:
      config in interface HeaderConverter
      Returns:
      the configuration specification; may not be null
    • configure

      public void configure​(Map<String,​?> configs)
      Description copied from interface: Configurable
      Configure this class with the given key-value pairs
      Specified by:
      configure in interface Configurable
    • configure

      public void configure​(Map<String,​?> configs, boolean isKey)
      Description copied from interface: Converter
      Configure this class.
      Specified by:
      configure in interface Converter
      Parameters:
      configs - configs in key/value pairs
      isKey - whether is for key or value
    • fromConnectData

      public byte[] fromConnectData​(String topic, Schema schema, Object value)
      Description copied from interface: Converter
      Convert a Kafka Connect data object to a native object for serialization.
      Specified by:
      fromConnectData in interface Converter
      Parameters:
      topic - the topic associated with the data
      schema - the schema for the value
      value - the value to convert
      Returns:
      the serialized value
    • toConnectData

      public SchemaAndValue toConnectData​(String topic, byte[] value)
      Description copied from interface: Converter
      Convert a native object to a Kafka Connect data object.
      Specified by:
      toConnectData in interface Converter
      Parameters:
      topic - the topic associated with the data
      value - the value to convert
      Returns:
      an object containing the Schema and the converted value
    • fromConnectHeader

      public byte[] fromConnectHeader​(String topic, String headerKey, Schema schema, Object value)
      Description copied from interface: HeaderConverter
      Convert the Header's value into its byte array representation.
      Specified by:
      fromConnectHeader in interface HeaderConverter
      Parameters:
      topic - the name of the topic for the record containing the header
      headerKey - the header's key; may not be null
      schema - the schema for the header's value; may be null
      value - 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: HeaderConverter
      Convert the header name and byte array value into a Header object.
      Specified by:
      toConnectHeader in interface HeaderConverter
      Parameters:
      topic - the name of the topic for the record containing the header
      headerKey - the header's key; may not be null
      value - the header's raw value; may be null
      Returns:
      the SchemaAndValue; may not be null
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable