avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincenz Priesnitz (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AVRO-1330) java: allow custom Encodings with annotations
Date Thu, 16 May 2013 09:43:15 GMT

    [ https://issues.apache.org/jira/browse/AVRO-1330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13659380#comment-13659380

Vincenz Priesnitz commented on AVRO-1330:

Thanks for the input. 

I renamed the classes as you proposed and and implemented the read method to return an instance.

Read can now be called with or without a reuse object.

The patch contains an encoding for Date which stores the value of Date.getTime(), i.e. milliseconds
since 1.1.1970. 

> 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
>         Attachments: Avro-1330.patch, Avro-1330update.patch
> 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

View raw message