[prev in list] [next in list] [prev in thread] [next in thread] 

List:       avro-user
Subject:    Re: Java code generation for nested non-optional records
From:       Teemu_Kanstrén <tkanstren () gmail ! com>
Date:       2015-08-21 16:28:50
Message-ID: CAGagL=erjMM=N1hXbgBYChr1q=+pmepBFrt0eDw5DCODK+Kgxw () mail ! gmail ! com
[Download RAW message or body]

Thanks! This works. So it was the extra [] left over from the optional
definition.

These schemas keep confusing me with all the combinations and braces.. :)

On 21 August 2015 at 18:28, Prajwal Tuladhar <praj@infynyxx.com> wrote:

> How about?
>
> {
>   "namespace": "avr=C3=B2.test",
>   "type": "record",
>   "name": "TopObj",
>   "fields": [
>     {
>       "name": "inner1",
>       "type": {
>         "name": "Inner1",
>         "type": "record",
>         "fields": [
>           {
>             "name": "value1",
>             "type": "string"
>           },
>           {
>             "name": "value2",
>             "type": "string"
>           }
>         ]
>       }
>     },
>     {
>       "name": "inner2",
>       "type": [
>         {
>           "type": "record",
>           "name": "Inner2",
>           "fields": [
>             {
>               "name": "value3",
>               "type": "string"
>             },
>             {
>               "name": "value4",
>               "type": "string"
>             }
>           ]
>         },
>         "null"
>       ]
>     }
>   ]
> }
>
>
> On Fri, Aug 21, 2015 at 3:00 PM, Teemu Kanstr=C3=A9n <tkanstren@gmail.com=
>
> wrote:
>
>> Hello all,
>>
>>  I am using the Maven Avro compiler to generate Java code for my Avro
>> schemas. Problem. If I have a nested record which is optional, everythin=
g
>> generates OK. If the type is not optional, the generated reference is se=
t
>> to generic Object type and I cannot use it. What might I be doing wrong?
>>
>>  Example schema:
>>
>> {
>>   "namespace": "avro.test",
>>   "type": "record",
>>   "name": "TopObj",
>>   "fields": [
>>     {"name": "inner1", "type": [
>>       {"type": "record", "name": "Inner1",
>>         "fields": [
>>           {"name": "value1", "type": "string"},
>>           {"name": "value2", "type": "string"}
>>         ]
>>       }]
>>     },
>>     {"name": "inner2", "type": [
>>       {"type": "record", "name": "Inner2",
>>         "fields": [
>>           {"name": "value3", "type": "string"},
>>           {"name": "value4", "type": "string"}
>>          ]
>>       }, "null"]
>>     }
>>   ]
>> }
>>
>> Running the Avro Java code generator for this produces three classes as =
expected: TopObj, Inner1 and Inner2. However, in TopObject, the definitions=
 are as:
>>
>> @Deprecated public java.lang.Object inner1;
>> @Deprecated public avro.test.Inner2 inner2;
>>
>> If I set inner1 as optional (add the , "null" to it) the type also becom=
es Inner1 in TopObj, which is as I would expect. But I do not want it to be=
 optional.
>>
>> How do I get inner1 to generate as type Inner1 in TopObj?
>>
>> Cheers & thanks,
>>
>> Teemu
>>
>>
>
>
> --
> --
> Cheers,
> Praj
>

[Attachment #3 (text/html)]

<div dir="ltr">Thanks! This works. So it was the extra [] left over from the optional \
definition.<div><br></div><div>These schemas keep confusing me with all the \
combinations and braces.. :)</div></div><div class="gmail_extra"><br><div \
class="gmail_quote">On 21 August 2015 at 18:28, Prajwal Tuladhar <span \
dir="ltr">&lt;<a href="mailto:praj@infynyxx.com" \
target="_blank">praj@infynyxx.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">How about?<div><br></div><div><pre>{  \
&quot;namespace&quot;: &quot;avrò.test&quot;,  &quot;type&quot;: &quot;record&quot;,
  &quot;name&quot;: &quot;TopObj&quot;,
  &quot;fields&quot;: [
    {
      &quot;name&quot;: &quot;inner1&quot;,
      &quot;type&quot;: {
        &quot;name&quot;: &quot;Inner1&quot;,
        &quot;type&quot;: &quot;record&quot;,
        &quot;fields&quot;: [
          {
            &quot;name&quot;: &quot;value1&quot;,
            &quot;type&quot;: &quot;string&quot;
          },
          {
            &quot;name&quot;: &quot;value2&quot;,
            &quot;type&quot;: &quot;string&quot;
          }
        ]
      }
    },
    {
      &quot;name&quot;: &quot;inner2&quot;,
      &quot;type&quot;: [
        {
          &quot;type&quot;: &quot;record&quot;,
          &quot;name&quot;: &quot;Inner2&quot;,
          &quot;fields&quot;: [
            {
              &quot;name&quot;: &quot;value3&quot;,
              &quot;type&quot;: &quot;string&quot;
            },
            {
              &quot;name&quot;: &quot;value4&quot;,
              &quot;type&quot;: &quot;string&quot;
            }
          ]
        },
        &quot;null&quot;
      ]
    }
  ]
}</pre>

<div align="center"></div></div></div><div class="gmail_extra"><div><div \
class="h5"><br><div class="gmail_quote">On Fri, Aug 21, 2015 at 3:00 PM, Teemu \
Kanstrén <span dir="ltr">&lt;<a href="mailto:tkanstren@gmail.com" \
target="_blank">tkanstren@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Hello all,<div><br></div><div>  I am using the \
Maven Avro compiler to generate Java code for my Avro schemas. Problem. If I have a \
nested record which is optional, everything generates OK. If the type is not \
optional, the generated reference is set to generic Object type and I cannot use it. \
What might I be doing wrong?</div><div><br></div><div>  Example \
schema:</div><div><br></div><div><pre \
style="color:rgb(0,0,0);font-family:&#39;Courier New&#39;">{<br>  <span \
style="color:#660e7a;font-weight:bold">&quot;namespace&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;avro.test&quot;</span>,<br>  <span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;record&quot;</span>,<br>  <span \
style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;TopObj&quot;</span>,<br>  <span \
style="color:#660e7a;font-weight:bold">&quot;fields&quot;</span>: [<br>    {<span \
style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;inner1&quot;</span>, <span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: [<br>      {<span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;record&quot;</span>, <span \
style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;Inner1&quot;</span>,<br>        <span \
style="color:#660e7a;font-weight:bold">&quot;fields&quot;</span>: [<br>          \
{<span style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;value1&quot;</span>, <span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;string&quot;</span>},<br>          \
{<span style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;value2&quot;</span>, <span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;string&quot;</span>}<br>        ]<br>    \
}]<br>    },<br>    {<span \
style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;inner2&quot;</span>, <span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: [<br>      {<span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;record&quot;</span>, <span \
style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;Inner2&quot;</span>,<br>        <span \
style="color:#660e7a;font-weight:bold">&quot;fields&quot;</span>: [<br>          \
{<span style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;value3&quot;</span>, <span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;string&quot;</span>},<br>          \
{<span style="color:#660e7a;font-weight:bold">&quot;name&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;value4&quot;</span>, <span \
style="color:#660e7a;font-weight:bold">&quot;type&quot;</span>: <span \
style="color:#008000;font-weight:bold">&quot;string&quot;</span>}<br>         ]<br>   \
}, <span style="color:#008000;font-weight:bold">&quot;null&quot;</span>]<br>    }<br> \
]<br>}</pre><pre style="color:rgb(0,0,0);font-family:&#39;Courier New&#39;"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">Running \
the Avro Java code generator for this produces three classes as expected: TopObj, \
Inner1 and Inner2. However, in TopObject, the definitions are \
as:</span><br></pre><pre style="color:rgb(0,0,0);font-family:&#39;Courier \
New&#39;"><pre style="font-family:&#39;Courier New&#39;"><span \
style="color:#808000">@Deprecated </span><span \
style="color:#000080;font-weight:bold">public </span>java.lang.Object <span \
style="color:#660e7a;font-weight:bold">inner1</span>;<br><span \
style="color:#808000">@Deprecated </span><span \
style="color:#000080;font-weight:bold">public </span>avro.test.Inner2 <span \
style="color:#660e7a;font-weight:bold">inner2</span>;<br></pre><pre \
style="font-family:&#39;Courier New&#39;"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">If I set \
inner1 as optional (add the , &quot;null&quot; to it) the type also becomes Inner1 in \
TopObj, which is as I would expect. But I do not want it to be \
optional.</span></pre><pre style="font-family:&#39;Courier New&#39;"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">How do I \
get inner1 to generate as type Inner1 in TopObj?  </span></pre><pre \
style="font-family:&#39;Courier New&#39;"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">Cheers \
&amp; thanks,</span></pre><pre style="font-family:&#39;Courier New&#39;"><span \
style="color:rgb(34,34,34);font-family:arial,sans-serif;white-space:normal">Teemu</span></pre></pre></div></div>
 </blockquote></div><br><br clear="all"><div><br></div></div></div><span \
class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr"><div><div \
dir="ltr">--<br></div><div>Cheers,<br></div><div>Praj<br></div></div></div></div> \
</font></span></div> </blockquote></div><br></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic