title: How to insert data into Avro Union/Map type
body: <p>Hi I'm trying to fill my record based on Avro schema using GenericRecord. But all the time when I'm trying to parse it by:</p>
  <pre><code>public static boolean validateJson(String json, Schema schema) throws Exception {
          InputStream input = new ByteArrayInputStream(json.getBytes());
          DataInputStream din = new DataInputStream(input);
  
          try {
              DatumReader reader = new GenericDatumReader(schema);
              Decoder decoder = DecoderFactory.get().jsonDecoder(schema, din);
              reader.read(null, decoder);
              return true;
          } catch (AvroTypeException e) {
              System.out.println(e.getMessage());
              return false;
          }
      }
  
  </code></pre>
  <p>I'm getting &quot;not a Union type.&quot;</p>
  <pre><code>schema.avsc
  &quot;type&quot;: &quot;record&quot;,
      &quot;namespace&quot;: &quot;com.acme&quot;,
      &quot;name&quot;: &quot;Test&quot;,
      &quot;fields&quot;: [
          { &quot;name&quot;: &quot;Country&quot;, &quot;type&quot;: &quot;string&quot; },
          { &quot;name&quot;: &quot;eventContextMetadata&quot;, &quot;type&quot;: [&quot;null&quot;, {&quot;type&quot;: &quot;map&quot;, &quot;values&quot;: &quot;string&quot; }]}
          
          ]
  }
  </code></pre>
  <p>Do someone know how to put this:</p>
  <pre><code> { &quot;name&quot;: &quot;eventContextMetadata&quot;, &quot;type&quot;: [&quot;null&quot;, {&quot;type&quot;: &quot;map&quot;, &quot;values&quot;: &quot;string&quot; }]}
  </code></pre>
  <p>into Record:</p>
  <p>avroRecord.put(&quot;eventContextMetadata&quot;, ??????);  or difernd method.</p>
  <p>and how to create a Map and Union?</p>