Return-Path: X-Original-To: apmail-avro-dev-archive@www.apache.org Delivered-To: apmail-avro-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BBC5FD308 for ; Thu, 16 May 2013 09:43:18 +0000 (UTC) Received: (qmail 24256 invoked by uid 500); 16 May 2013 09:43:17 -0000 Delivered-To: apmail-avro-dev-archive@avro.apache.org Received: (qmail 24029 invoked by uid 500); 16 May 2013 09:43:17 -0000 Mailing-List: contact dev-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list dev@avro.apache.org Received: (qmail 23695 invoked by uid 99); 16 May 2013 09:43:15 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 May 2013 09:43:15 +0000 Date: Thu, 16 May 2013 09:43:15 +0000 (UTC) From: "Vincenz Priesnitz (JIRA)" To: dev@avro.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (AVRO-1330) java: allow custom Encodings with annotations MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ 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 { > { > 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