Are you still having trouble with this?  I noticed that the code has changed and you are using MyPair instead of Pair.  Was there a naming conflict bug with Avro's  


On 9/2/11 3:46 PM, "W.P. McNeill" <> wrote:

I made changes that got rid of all the deprecated calls.  I think I am using the 1.5 interface correctly.  However, I get a runtime error when I try to deserialize into a class using a SpecificDataumReader.  The problem starts at line 62 of  The code looks like this:

      DatumReader<Pair> reader = new SpecificDatumReader<Pair>(Pair.class);
      BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(out.toByteArray(), null);
      Pair result =, decoder);
      System.out.printf("Left: %s, Right: %s\n", result.left, result.right);

Where Pair is an object I have SpecificRecord that I have in this project. When I deserialize with I get the following runtime error:

Exception in thread "main" java.lang.ClassCastException: org.apache.avro.generic.GenericData$Record cannot be cast to wpmcn.Pair
at wpmcn.AvroExample.serializeSpecific(
at wpmcn.AvroExample.main(

When I step into the debugger I see that the function has type D as GenericData.

Presumably I'm calling something wrong but I can't figure out what.

On Fri, Sep 2, 2011 at 3:02 PM, Philip Zeyliger <> wrote:

I encourage you to file a JIRA and submit a patch to AVRO.  Having example code in the code base seems like a win to me.

-- Philip

On Fri, Sep 2, 2011 at 2:41 PM, W.P. McNeill <> wrote:
I'm new to Avro. Since I'm having trouble finding simple examples online I'm writing one of my own that I'm putting on github.

Hopefully, this will be of help to people like me who are also having trouble finding simple code examples.

I want to get this compiling without of hitch in Maven. I had it running with a 1.4 version of Avro, but when I changed that to 1.5, some of the code no longer works. Specifically, BinaryEncoder can no longer be instantiated directly because it is now an abstract class ( line 33) and DecoderFactory.defaultFactory is deprecated ( line 41).

How should I modify this code so that it works with the latest and greatest version of Avro?  I looked through the Release Notes, but the answers weren't obvious.