avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Bates <johntba...@gmail.com>
Subject robustness of Schema.Field.pos() across schema versions
Date Wed, 06 Jun 2012 20:08:04 GMT
Hi, all.

I'm trying to subclass an Avro IDL-generated class so that it may
implement an interface used by our project to deserialize data (and
not necessarily Avro data) from an InputStream.  Ideally, I'd like to
do something like this:

public class MySubclass extends MyAvroGeneratedClass implements
MySerializationInterface {
  public void readObject(InputStream in) throws IOException,
      ClassNotFoundException {

    // AvroUtil.readObject exists and returns a SpecificRecord given
an InputStream and Schema
    MySubclass other = ((MyAvroGeneratedClass) AvroUtil.readObject(in,

    // Is this correct?  Is it robust?
    List<Schema.Field> fields = other.getSchema().getFields();
    for(Schema.Field field : fields) {
      int position = field.pos();
      this.put(position, other.get(position));

I'm trying to avoid having to use the setters and getters supplied by
the generated class, as that will require this subclass remains in
sync with the IDL-generated class, which will probably be a point of

Is this approach robust to changes in the schema?  That is, if the
schema changes at some point in the future, will it be possible to
deserialize data that has been serialized with an older version of the
schema?  Is there a better (read: more correct, more robust, more
consistent with Avro's design) way to do this?

I sincerely appreciate your help - I've been blocked for a few days on this.

Thanks in advance,
John Bates

View raw message