Class SimpleConsumeKeyValueDeserializer
java.lang.Object
io.confluent.kafkarest.utils.SimpleConsumeKeyValueDeserializer
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectjsonFromBytes(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: IfreturnRawBase64Recordsistrue, 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.
-
Field Details
-
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
- See Also:
-
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:- 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
returnRawBase64Recordsistrue, 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.
Special cases:
- If
bytesisnull, returnsnull(tombstone record). - If
bytesis empty, returns an empty string.
- Parameters:
bytes- the byte array to deserialize; may benullor emptykafkaHeaders- the Kafka headers associated with the recordisKey-trueif the bytes represent a key;falsefor a valuereturnRawBase64Records- iftrue, 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
-