Details
-
New Feature
-
Status: Resolved
-
Minor
-
Resolution: Duplicate
-
None
-
None
-
None
Description
I propose an annotation @AvroEncode that allows one to encode a java field or a class directly. The motivation behind this is that some classes are impossible to serialize due to transient fields or result in a verbose encoding. For example, java.util.Date cannot be serialized as of now.
The annotation would specify an implementation of an abstract serializer/deserializer class, which reads and writes directly from the encoder/decoder.
It would also insert the encodings schema into the surrounding schema.
The annotation would look like this:
@AvroEncode(using=DateToUtcMillisecondsSerDe) Date date;
public class DateToUtcMillisecondsSerDe extends CustomSerDe<Date> { { schema = Schema.create(Schema.Type.LONG); } @Override void write(Date datum, Encoder out) throws IOException { out.writeLong(datum.getTime()); } @Override void read(Date datum, Decoder in) throws IOException { datum.setTime(in.readLong()); } }
As a proof of concept, i implemented such a serDe for java.util.Date.
this would solve avro-739 by delivering one or several default formats for Date, which can be Overridden to any representation by implemeting a different SerDe.