Class SimpleConsumeKeyValueDeserializer

java.lang.Object
io.confluent.kafkarest.utils.SimpleConsumeKeyValueDeserializer

public final class SimpleConsumeKeyValueDeserializer extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final String
     
    static final String
    The name of the property containing the raw Base64-encoded data of the schema-encoded key or value.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Object
    jsonFromBytes(byte[] bytes, org.apache.kafka.common.header.Headers kafkaHeaders, boolean isKey, boolean returnRawBase64Records)
    Deserializes a byte array into a JSON-compatible object, determining whether to return the raw bytes (as a Base64-encoded string in a JSON object) or a UTF-8 string, based on the following order of precedence: Header check: If the Kafka headers contain a schema ID for the key or value, the raw bytes are returned as a Base64-encoded string in a JSON object. Magic byte: If the first byte matches the expected magic byte, the raw bytes are returned as a Base64-encoded string in a JSON object. Query parameter: If returnRawBase64Records is true, the raw bytes are returned as a Base64-encoded string in a JSON object. UTF-8 string: Otherwise, the bytes are interpreted as a UTF-8 string and returned as such.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • RAW_DATA_PROPERTY

      public static final String RAW_DATA_PROPERTY
      The name of the property containing the raw Base64-encoded data of the schema-encoded key or value.
      See Also:
    • KAFKA_HEADERS_KEY_FOR_KEY_SCHEMA_ID

      public static final String KAFKA_HEADERS_KEY_FOR_KEY_SCHEMA_ID
      See Also:
    • KAFKA_HEADERS_KEY_FOR_VALUE_SCHEMA_ID

      public static final String KAFKA_HEADERS_KEY_FOR_VALUE_SCHEMA_ID
      See Also:
  • Constructor Details

    • SimpleConsumeKeyValueDeserializer

      public SimpleConsumeKeyValueDeserializer()
  • Method Details

    • jsonFromBytes

      public static Object jsonFromBytes(byte[] bytes, org.apache.kafka.common.header.Headers kafkaHeaders, boolean isKey, boolean returnRawBase64Records)
      Deserializes a byte array into a JSON-compatible object, determining whether to return the raw bytes (as a Base64-encoded string in a JSON object) or a UTF-8 string, based on the following order of precedence:
      1. Header check: If the Kafka headers contain a schema ID for the key or value, the raw bytes are returned as a Base64-encoded string in a JSON object.
      2. Magic byte: If the first byte matches the expected magic byte, the raw bytes are returned as a Base64-encoded string in a JSON object.
      3. Query parameter: If returnRawBase64Records is true, the raw bytes are returned as a Base64-encoded string in a JSON object.
      4. UTF-8 string: Otherwise, the bytes are interpreted as a UTF-8 string and returned as such.

      Special cases:

      • If bytes is null, returns null (tombstone record).
      • If bytes is empty, returns an empty string.
      Parameters:
      bytes - the byte array to deserialize; may be null or empty
      kafkaHeaders - the Kafka headers associated with the record
      isKey - true if the bytes represent a key; false for a value
      returnRawBase64Records - if true, always return the raw bytes as a Base64-encoded string in a JSON object
      Returns:
      the deserialized value: null, an empty string, a JSON object with a Base64-encoded string, or a UTF-8 string