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:

http://avro.apache.org/docs/current/api/java/org/apache/avro/reflect/Nullable.html

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; }
}

Doug

Reply via email to