avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcus Simonsen <msimon...@gmail.com>
Subject DateAsLongEncoding Decoding error
Date Mon, 06 Feb 2017 15:23:24 GMT
Hello.
I was very excited to start using the avro reflection serialization API!

I am however unable to properly use the annotation to customized encoding:

Here in my java bean I've used:

@AvroEncode(using = DateAsLongEncoding.class)
    private Date ts;


And then use the DatumWriter (successfully):
ByteArrayOutputStream bout = new ByteArrayOutputStream();

            DatumWriter<T> writer =
ReflectData.AllowNull.get().createDatumWriter(schema);
            BinaryEncoder encoder =
EncoderFactory.get().directBinaryEncoder(bout, null);
            writer.write(obj, encoder);
            encoder.flush();
             byte[]    serialized = bout.toByteArray();

But fails:
        DatumReader<T> reader =
ReflectData.AllowNull.get().createDatumReader(schema);

        BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(b, null);

        return reader.read(null, decoder);  //throws Exception

Stack Trace:

Caused by: java.io.IOException: Invalid int encoding
    at org.apache.avro.io.BinaryDecoder.readInt(BinaryDecoder.java:145)
    at org.apache.avro.io.BinaryDecoder.readIndex(BinaryDecoder.java:423)
    at
org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:290)
    at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)
    at
org.apache.avro.io.ResolvingDecoder.readLong(ResolvingDecoder.java:155)
    at
org.apache.avro.reflect.DateAsLongEncoding.read(DateAsLongEncoding.java:50)
    at
org.apache.avro.reflect.DateAsLongEncoding.read(DateAsLongEncoding.java:33)
    at org.apache.avro.reflect.CustomEncoding.read(CustomEncoding.java:45)
    at
org.apache.avro.reflect.FieldAccessUnsafe$UnsafeCustomEncodedField.read(FieldAccessUnsafe.java:353)
    at
org.apache.avro.reflect.ReflectDatumReader.readField(ReflectDatumReader.java:272)
    at
org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:230)
    at
org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:174)
    at
org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
    at
org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:144)

    ... 25 more

Mime
View raw message