Hi, To see how it would work I simply wrote the patch and played in my environment with the effects on the generated Java code. [ I created a Jira issue and attached this draft patch to it: https://issues.apache.org/jira/browse/AVRO-1614 ]
The idea works but I also found that for my usecase it is not very pleasant to work with. Assume this example again: public void setSomething(String value) { myStruct .getAlwaysFoo() .getAlwaysBar() .getAlwaysOne() .getAlwaysOther() .setSomething(value); } The main problem is that in order to do .getAlwaysOne() I MUST define ALL fields of that type with a default value. What I don;t like about that is that I want the schema definition to enforce the fact that some fields are mandatory. By adding a default value to 'everything' I lose that capability of AVRO ... which I don't want. At this point in time the only workaround this (for me major) issue is by introducing something where I can do something like having a 'tree of incomplete Builders' and when I say 'build()' to the top one it will build the entire tree. Any thoughts? Do you guy think there is a need/usecase for this idea (so I leave the issue open) or shall I simply close AVRO-1614 with a 'Won't fix'? Niels Basjes On Thu, Nov 27, 2014 at 1:37 AM, Doug Cutting <cutt...@apache.org> wrote: > On Wed, Nov 26, 2014 at 2:33 PM, svante karlsson <s...@csi.se> wrote: > > I'm not sure that works for avro where null is used for an optional > field. > > It should work. If it doesn't, it's a bug. For example: > > record Foo { > union {string, null} name = "default"; > } > > record Bar { > union {Foo, null} foo = {"name" = "non-default"}; > } > > Default values in IDL are JSON format. > > Doug > -- Best regards / Met vriendelijke groeten, Niels Basjes