[ 
https://issues.apache.org/jira/browse/AVRO-1274?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13602789#comment-13602789
 ] 

Doug Cutting commented on AVRO-1274:
------------------------------------

Defaults are primarily used at read time to supply values for fields missing 
from the writer's schema.

The builder API will also fill in default values at object creation time (i.e., 
prior to write, typically).  To build generic instances with defaults use 
GenericRecordBuilder.  For example:

with the schema:

{code}
{"type":"record", "name":"r", "fields":[{"name":"f", "type":"int", 
"default":0}]}
{code}

then you should see:

{code}
new GenericRecordBuilder(schema).build().toString() -> {"f", 0}

new GenericRecordBuilder(schema).set("f",1).build().toString() -> {"f", 1}
{code}


                
> Add a schema builder API
> ------------------------
>
>                 Key: AVRO-1274
>                 URL: https://issues.apache.org/jira/browse/AVRO-1274
>             Project: Avro
>          Issue Type: New Feature
>          Components: java
>            Reporter: Tom White
>            Assignee: Tom White
>         Attachments: AVRO-1274.patch, AVRO-1274.patch, AVRO-1274.patch, 
> TestDefaults.patch
>
>
> It would be nice to have a fluent API that made it easier to construct record 
> schemas.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to