Thank you. I'm using the Python API. It seems record builder is not available. But it is good to know the general approach for initializing with default value.

Wai Yip

Christophe Taton wrote:

Hi,
I'd suggest using the record builders to construct your records:
record builders will initialize fields with their default values if
you don't set them.
C.

On Wed, Feb 19, 2014 at 9:07 AM, Gary Steelman
<[email protected] <mailto:[email protected]>> wrote:

Hey Wai,

Good question. I've had that problem recently too. My solution has
been to set the missing field to a known default value in my code
before I try to serialize an object. That is, if some integer is
required by the schema, I do a check on my object.

if (myObject.value == null) {myObject.value = -1;}

But then you have to do this for all fields in the schema which
aren't optional. And that's kind of a pain. It'd be kind of nice
if the writer also used the default value from the schema for
writing.

Thanks,
Gary

On Feb 19, 2014 10:42 AM, "Wai Yip Tung" <[email protected]
<mailto:[email protected]>> wrote:

In the schema we can define a "default" value. It is used as
default when reading. If the field is missing from the data
when we write, it results in an error. Is there a counterpart
of "default" in writing so that if the field is missing, the
writer just fill in the default value?

Wai Yip

Reply via email to