[
https://issues.apache.org/jira/browse/AVRO-1330?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13658856#comment-13658856
]
Doug Cutting commented on AVRO-1330:
------------------------------------
Nice idea.
- I don't think we should use the term "SerDe", since that's used in Hive and
could be confusing here. Rather we might call these encodings, e.g.,
CustomEncoding, DateAsLongEncoding, etc.
- The patch only currently works for field values, not for top-level values or
for, e.g., values in a Map. The 'read' method in the Encoding interface should
thus probably return a value rather than always mutating a passed-in value.
- We might pre-define some encodings for built-in types like Date.
> 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
>
>
> 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