title: How to convert from GenericRecord to SpecificRecord in Avro for compatible schemas
body: <p>Is the Avro SpecificRecord (i.e. the generated java classes) compatible with schema evolution?  I.e. if I have a source of Avro messages (in my case, kafka) and I want to deserialize those messages to a specificrecord, is it possible to do safely?</p>
  
  <p>What I see:</p>
  
  <ul>
  <li>adding a field to the end of a schema works fine - can deserialize ok to specificrecord</li>
  <li>adding a field to the middle does not - i.e. breaks existing clients</li>
  </ul>
  
  <p>Even if the messages are compatible, this is a problem. </p>
  
  <p>If I can find the new schema (using e.g. confluent schema registry) I can deserialize to GenericRecord, but there doesn't seem to be a way to map from genericrecord to specificrecord of different schema..</p>
  
  <pre><code>MySpecificType message = (T SpecificData.get().deepCopy(MySpecificType.SCHEMA$, genericMessage);
  </code></pre>
  
  <p>Deepcopy is mentioned in various places but it uses index so doesn't work..</p>
  
  <p>Is there any safe way to map between two avro objects when you have both schemas and they are compatible?  Even if I could map from genercrecord to genericrecord this would do as I could then do the deepcopy trick to complete the job.</p>