title: AVRO - Complex Records with Union Record type support
body: <p>I am trying to build an AVRO's complex record with Union data type supported member record type.</p>
  <pre><code>{
      &quot;namespace&quot;: &quot;proj.avro&quot;,
      &quot;protocol&quot;: &quot;app_messages&quot;,
      &quot;doc&quot; : &quot;application messages&quot;,
      
      &quot;types&quot;: [
          {
              &quot;name&quot;: &quot;record_request&quot;,
              &quot;type&quot; : &quot;record&quot;, 
              &quot;fields&quot;: 
              [
                  {
                      &quot;name&quot; : &quot;request_id&quot;, 
                      &quot;type&quot; : &quot;int&quot;
                  },
                  {
                      &quot;name&quot; : &quot;message_type&quot;,
                      &quot;type&quot; : int,
                  },
                  {
                      &quot;name&quot; : &quot;users&quot;,
                      &quot;type&quot; : &quot;string&quot;
                  }
              ]
          },
          {
              &quot;name&quot; : &quot;request_response&quot;,
              &quot;type&quot; : &quot;record&quot;,
              &quot;fields&quot; :
              [
                  {
                      &quot;name&quot; : &quot;request_id&quot;,
                      &quot;type&quot; : &quot;int&quot;
                  },
                  {
                      &quot;name&quot; : &quot;response_code&quot;,
                      &quot;type&quot; : &quot;string&quot;
                  },
                  {
                      &quot;name&quot; : &quot;response_count&quot;,
                      &quot;type&quot; : &quot;int&quot;
                  },
                  {
                      &quot;name&quot; : &quot;reason_code&quot;,
                      &quot;type&quot; : &quot;string&quot;
                  }
              ]
          }
      ]
      
      &quot;messages&quot; :
      {
          &quot;published_msgs&quot; :
          {
              &quot;doc&quot; : &quot;My Messages&quot;,
              &quot;fields&quot; :
              [
                  {
                      &quot;name&quot; : &quot;message_type&quot;,
                      &quot;type&quot; : &quot;int&quot;
                  },
                  {
                      &quot;name&quot; : &quot;message_body&quot;,
                      &quot;type&quot; : 
                      [
                          &quot;record_request&quot;, &quot;request_response&quot;
                      ]
                  }
              ]
              
          }
      }
  }
  </code></pre>
  <p>I am getting error while trying to read this kind of schema.</p>
  <p>I would like to know - is it possible to declare such AVRO schema - which has one of field which type is union of complex user defined message structure.</p>
  <p>If its possible then could you please let me know what i am doing wrong or an example of such structure with union type field's type definition?</p>
  <p>I want to use AVRO's dynamically schema usage - so specify this schema file run-time and parse the incoming buffer as &quot;request&quot;/&quot;response&quot;.</p>
  <p>Thanks,</p>