Reading Avro file gives AvroTypeException: missing required field error (even though the new field is declared null in schema)
<p>I am trying to deserialize/read an Avro file, the avro data file doesn't have the new field. Even though the new field is declared as null in schema, it is expected to be optional. But it still gives me error as mandatory.</p>

<blockquote>
  <p>Exception in thread "main" org.apache.avro.AvroTypeException: Found com.kiran.avro.User, expecting com.kiran.avro.User, missing required field loc</p>
</blockquote>

<p>The AVRO schema declaration:</p>

<pre><code>{"name": "loc", "type": ["string", "null"]}
</code></pre>

<p>Reading file using code:</p>

<pre><code>DatumReader&lt;User&gt; userDatumReader = new SpecificDatumReader&lt;User&gt;(User.class);
DataFileReader&lt;User&gt; dataFileReader = new DataFileReader&lt;User&gt;(file, userDatumReader);
</code></pre>

<p>Is there any other way to declare an optional field?</p>

<p>Thanks for hints/suggestions !!</p>