Return-Path: X-Original-To: apmail-avro-dev-archive@www.apache.org Delivered-To: apmail-avro-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 046AEE416 for ; Wed, 27 Feb 2013 19:59:14 +0000 (UTC) Received: (qmail 84224 invoked by uid 500); 27 Feb 2013 19:59:13 -0000 Delivered-To: apmail-avro-dev-archive@avro.apache.org Received: (qmail 84165 invoked by uid 500); 27 Feb 2013 19:59:13 -0000 Mailing-List: contact dev-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list dev@avro.apache.org Received: (qmail 84084 invoked by uid 99); 27 Feb 2013 19:59:13 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 27 Feb 2013 19:59:13 +0000 Date: Wed, 27 Feb 2013 19:59:13 +0000 (UTC) From: "Doug Cutting (JIRA)" To: dev@avro.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (AVRO-1261) Honor schema defaults with the Constructor in addition to the builders. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/AVRO-1261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13588693#comment-13588693 ] Doug Cutting commented on AVRO-1261: ------------------------------------ The no-arg constructor is also used to create instances when reading. Setting field defaults in this case may harm performance, especially when new copies of mutable default values are allocated each time. Similarly, setting field values to defaults when writing may harm performance when the application overwrites the default. In general, there are cases where it's probably fastest to create instances without defaults set. Currently the no-arg constructor serves this purpose and the Builder API supports the case where defaults are desired. Perhaps we could better document this? The generated no-arg constructor might include javadoc cautioning that no default values are set and that the builder should be used if they're desired? > Honor schema defaults with the Constructor in addition to the builders. > ----------------------------------------------------------------------- > > Key: AVRO-1261 > URL: https://issues.apache.org/jira/browse/AVRO-1261 > Project: Avro > Issue Type: Bug > Components: java > Affects Versions: 1.7.4 > Reporter: Christopher Conner > Priority: Minor > > As I understand it, currently if you want to utilize defaults in a schema, ie: > { > "namespace": "com.chris.test", > "type": "record", > "name": "CHRISTEST", > "doc": "Chris Test", > "fields": [ > {"name": "firstname", "type": "string", "default": "Chris"}, > {"name": "lastname", "type": "string", "default": "Conner"}, > {"name": "username", "type": "string", "default": "cconner"} > ] > } > Then I have to use the builders to create my objects. IE: > public class ChrisAvroTest { > public static void main(String[] args) throws Exception { > CHRISTEST person = CHRISTEST.newBuilder() > .build(); > System.out.println("person:" + person); > } > } > Is my understanding correct? Is it possible to make it so the default constructor as well? -- 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