avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Carey <scottca...@apache.org>
Subject Re: How to add optional new record fields and/or new methods in avro-ipc?
Date Tue, 18 Oct 2011 17:09:30 GMT
On 10/18/11 9:47 AM, "Doug Cutting" <cutting@apache.org> wrote:

>On 10/17/2011 08:14 PM, 常冰琳 wrote:
>> What I do in the demo is add a new nullable string in server side, not
>> change a string to nullable string.
>> I add a new field with default value using specific, and it works fine,
>> so I suspect the reason that reflect doesn't work is that I didn't add
>> default value to the nullable string field.
>> Perhaps the default value for nullable field should be null by default?
>Reflect by default assumes that all values are not nullable.  This is
>perhaps a bug, but the alternative is to make every non-numeric value
>nullable, which would result in verbose schemas.
>To amend this, you can use Avro's @Nullable annotation:
>This can be applied to parameters, return types and fields.
>For example:
>import org.apache.avro.reflect.Nullable;
>public class Foo {
>  @Nullable String x;
>  public void setX(@Nullable String x) { this.x = x; }
>  @Nullable public String getX() { return x; }

The problem is that this does not provide the ability to evolve schemas if
you add a field
since you would need @Default or something similar, as well:

Does reflect have any concept of default values?


View raw message