You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Vincenz Priesnitz (JIRA)" <ji...@apache.org> on 2013/05/15 16:17:16 UTC
[jira] [Commented] (AVRO-1330) java: allow custom Encodings with
annotations
[ https://issues.apache.org/jira/browse/AVRO-1330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13658389#comment-13658389 ]
Vincenz Priesnitz commented on AVRO-1330:
-----------------------------------------
Here is a patch that implements proposed features.
> 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