This page describes how to use deserializers in Lenses.
Lenses works out of the box with any messages in AVRO, JSON, XML and primitive formats.
When using messages with other formats like Google Protobuf or Thrift, you need to provide a deserialization envelop or else a serde
. A serde handles reading raw bytes into a meaningful data structure and translating data into raw bytes based on the storage format.
For example, a Kafka topic contains GPS coordinates, including a latitude and a longitude stored as double. Each “latitude:longitude” string, such as “45.623412:10.419433” is converted to UTF8 bytes, and published to a topic in Protobuf format.
A serde can enable us to decode/encode this format. This can be achieved via a simple API. First, use the following library dependency:
Check the following Java code that implements a Serde interface that has two methods. The return type of the deserializer is a GenericRecord
with the two fields parsed from the bytes.
In this simple example, we do not worry about error handling, such as ensuring that the tokens have valid double values.
Serialization using custom formats is not currently supported by Lenses so there is no requirement to implement the serializer method.