[
https://issues.apache.org/jira/browse/AVRO-2730?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Anh Le resolved AVRO-2730.
--------------------------
Resolution: Fixed
> Union: validating default values
> --------------------------------
>
> Key: AVRO-2730
> URL: https://issues.apache.org/jira/browse/AVRO-2730
> Project: Apache Avro
> Issue Type: Wish
> Components: spec
> Reporter: Anh Le
> Priority: Minor
>
> Hi guys,
> I'm trying to set the default value for a field (using Java) and I've got a
> nasty exception:
> {noformat}
> Exception in thread "main" org.apache.avro.AvroTypeException: Invalid default
> for field first: "Andy" not a ["null","string"]
> at org.apache.avro.Schema.validateDefault(Schema.java:1542)
> ...{noformat}
> In the documentation of Apache Avro: Unions
> {noformat}
> Unions, as mentioned above, are represented using JSON arrays. For example,
> ["null", "string"] declares a schema which may be either a null or string.
> (Note that when a default value is specified for a record field whose type is
> a union, the type of the default value must match the first element of the
> union. Thus, for unions containing "null", the "null" is usually listed
> first, since the default value of such unions is typically null.)
> {noformat}
> Would you please tell me why the type of the default value must match the
> first element of the union? Is it better if the value match any element?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)