title: Transform protobuf to avro
body: <p>I have data serialized in protobuff format and I want to transform it to an Avro serialization.</p>
  
  <p>I have no problem reading the proto data using</p>
  
  <pre><code>    ProtoTest.Msg msg = buildMessage();
      ProtobufData protobufData = ProtobufData.get();
      Schema protoSchema = protobufData.getSchema(ProtoTest.Msg.class);
      Object o = protobufData.newRecord(msg, protoSchema);
  </code></pre>
  
  <p>The resulting <strong><em>o</em></strong> is again a protobuf object. Now I want to write <strong><em>o</em></strong> as avro with the same schema</p>
  
  <pre><code>    GenericDatumWriter genericDatumWriter = new GenericDatumWriter(protoSchema);
      OutputStream out = new ByteArrayOutputStream();
      Encoder encoder = EncoderFactory.get().binaryEncoder(out, null );
      genericDatumWriter.write(o, encoder);
  </code></pre>
  
  <p>But running the code above throws next exception at the <em>write</em> method</p>
  
  <pre><code>java.lang.ClassCastException: example.avro.ProtoTest$Msg cannot be cast to org.apache.avro.generic.IndexedRecord
  at org.apache.avro.generic.GenericData.getField(GenericData.java:526)
  at org.apache.avro.generic.GenericData.getField(GenericData.java:541)
  at org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:104)
  at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:66)
  at org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:58)
  at hermes.mediationOrchestrator.AvroFileWriteTest.testWriter3(AvroFileWriteTest.java:115)
  </code></pre>
  
  <p>How can I transform proto object into avro object?</p>
  
  <p>Regards,
    Ronen.</p>