Avro Conversions are not being called for extensions of Encoder

176 Views Asked by At

I am trying to implement a ZonedDateTime conversion very similar to this post: https://stackoverflow.com/a/70088424/3926131

What I have noticed is that the toCharSequence method only gets called from classes that implement the avro MessageEncoder interface(e.g. BinaryMessageEncoder) but will not be called when I use a class that extends the avro Encoder abstract class (e.g. BinaryEncoder)

@Override
public CharSequence toCharSequence(ZonedDateTime value, Schema schema, LogicalType type) {
    return value.format(DATE_TIME_FORMATTER);
}  

Does anyone know if it is possible to use avro conversions for encoders that extend Encoder?

1

There are 1 best solutions below

0
JoeyHolloway On

I found the issue - you need to use a datatum writer constructor that takes the schema and data e.g.

public ReflectDatumWriter(Schema root, ReflectData reflectData) {
    super(root, reflectData);
}