Return-Path: X-Original-To: apmail-avro-user-archive@www.apache.org Delivered-To: apmail-avro-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EA78610995 for ; Sun, 20 Oct 2013 20:28:30 +0000 (UTC) Received: (qmail 6478 invoked by uid 500); 20 Oct 2013 20:28:30 -0000 Delivered-To: apmail-avro-user-archive@avro.apache.org Received: (qmail 6315 invoked by uid 500); 20 Oct 2013 20:28:30 -0000 Mailing-List: contact user-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@avro.apache.org Delivered-To: mailing list user@avro.apache.org Received: (qmail 6307 invoked by uid 99); 20 Oct 2013 20:28:29 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Oct 2013 20:28:29 +0000 Received: from localhost (HELO mail-pd0-f178.google.com) (127.0.0.1) (smtp-auth username cutting, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Oct 2013 20:28:29 +0000 Received: by mail-pd0-f178.google.com with SMTP id w10so7340653pde.37 for ; Sun, 20 Oct 2013 13:28:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=4E8pYBOqhhbD9fJpBBBFYyLCyhmA1tF3yXwHilSI57I=; b=LvVLP2B5b5+drT54rGQobf3TPEEIyvzhqmzNOODCh+Px7V69udJD97m1ItQrHSlHoS 0vFOe06rKhmhO6lzWtyhlkXMUe/8Z2ZZ4PoZcOuZz5KrMfKty2tR9vR3MdzIKfte8NHL +6SWUrk1qG/QrBL1VLhf9KVvP905RCIZxz0CJNmQwu9/PPb8hyJvLYrieFdx36rrOTOT QbTTiBJwQyDznwoPOD4YJcjigQ70RSHlMuBPxXK/n8UQ9ybRlWRndbJamAL2115s+KcD pxUENQeroRwyW+lB3p9iq1p3dMkW2MRO54q3QHb89p3VOTOEQzXMghMpR+0UQWJsN6hb sSig== MIME-Version: 1.0 X-Received: by 10.68.227.36 with SMTP id rx4mr2946453pbc.128.1382300908842; Sun, 20 Oct 2013 13:28:28 -0700 (PDT) Received: by 10.70.65.138 with HTTP; Sun, 20 Oct 2013 13:28:28 -0700 (PDT) Received: by 10.70.65.138 with HTTP; Sun, 20 Oct 2013 13:28:28 -0700 (PDT) In-Reply-To: References: Date: Sun, 20 Oct 2013 13:28:28 -0700 Message-ID: Subject: Re: default values From: Doug Cutting To: user@avro.apache.org Content-Type: multipart/alternative; boundary=047d7b163257a4f71f04e9320235 --047d7b163257a4f71f04e9320235 Content-Type: text/plain; charset=UTF-8 Note that builders do supply defaults. http://avro.apache.org/docs/current/api/java/org/apache/avro/data/RecordBuilder.html But that might not help you much here. You might intersect your config json with the reader schema to determine its implied writer schema. Doug On Oct 13, 2013 9:21 PM, "Koert Kuipers" wrote: > i am testing parsing a json string using a record class defined in an > .avdl file. > > i was hoping that if a field in the record has a default value that it is > not mandatory to provide it in the json. however i get an exception: > > org.apache.avro.AvroTypeException: Expected field name not found: test123 > > i guess it was silly of me to expect this? > are default values only used in schema resolution (so reader vs writer > schema)? and in this case there is no writer schema, just json data i > created and a reader schema, so the default values will not help me? > > too bad because this seemed like a really quick and convenient way to > create configuration objects that can be instantiated from json, but > without "optional" fields with default values it loses a lot of it power. > > --047d7b163257a4f71f04e9320235 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

Note that builders do supply defaults.

http://avro.apache.org/docs/current/ap= i/java/org/apache/avro/data/RecordBuilder.html

But that might not help you much here.

You might intersect your config json with the reader schema = to determine its implied writer schema.

Doug

On Oct 13, 2013 9:21 PM, "Koert Kuipers&quo= t; <koert@tresata.com> wrote= :
i am testing parsing a json string using a record class defi= ned in an .avdl file.

i was hoping that if a field in the record has a default value that it is n= ot mandatory to provide it in the json. however i get an exception:

= org.apache.avro.AvroTypeException: Expected field name not found: test123
i guess it was silly of me to expect this?
are default values o= nly used in schema resolution (so reader vs writer schema)? and in this cas= e there is no writer schema, just json data i created and a reader schema, = so the default values will not help me?

too bad because this seemed like a really quick and convenient = way to create configuration objects that can be instantiated from json, but= without "optional" fields with default values it loses a lot of = it power.

--047d7b163257a4f71f04e9320235--