[ https://issues.apache.org/jira/browse/AVRO-1330?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Vincenz Priesnitz updated AVRO-1330: ------------------------------------ Status: Patch Available (was: Open) > java: allow custom Encodings with annotations > --------------------------------------------- > > Key: AVRO-1330 > URL: https://issues.apache.org/jira/browse/AVRO-1330 > Project: Avro > Issue Type: New Feature > Components: java > Reporter: Vincenz Priesnitz > Priority: Minor > > 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: > {code} > @AvroEncode(using=DateToUtcMillisecondsSerDe) > Date date; > {code} > {code} > 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()); > } > } > {code} > 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. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira