Relative Content

Tag Archive for javaavro

Enhanced switch for non-public classes

Occasionally a 3rd party library contains APIs that return non-public classes which you cannot reference directly. One such example is org.apache.avro.generic.GenericRecord.get() which can sometimes return a java.nio.HeapByteBuffer object. If I wanted to switch over that class like so I will get a compile error:

Avro, Schema Evolution, Backward-Compatibility

Avro specification declares that extending a schema with optional fields is backward-compatible. Unfortunately, it does not work with binary streams for us and I do not know how to fix it. I have written a simple demo app to demonstrate the problem. The producer creates an instance, serializes it, and saves it to a file and the consumer reads the file and deserializes the stream. If the optional field is added to the schema and the schema is compiled (maven plugin), then instances based on the previous version of the schema cannot be serialized. The behavior is different when we use DataFileWriter/Reader, in that case it works but we need binary streams as we use kafka and the messages contain the serialized data.