[
https://issues.apache.org/jira/browse/AVRO-3913?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17792180#comment-17792180
]
Joao Antonio commented on AVRO-3913:
------------------------------------
For the sake of clarity, both following schema should be valid:
{code:java}
{"type": "record", "name": "TestRecord", "fields": [{"name": "optionalField",
"type": ["null", "string"]}]}{code}
> Optional fields should not require a default value set to null
> --------------------------------------------------------------
>
> Key: AVRO-3913
> URL: https://issues.apache.org/jira/browse/AVRO-3913
> Project: Apache Avro
> Issue Type: Bug
> Components: java
> Reporter: Joao Antonio
> Priority: Major
>
> The Avro Schema Specification states that when a field has type Union, the
> type of its default value must match the first type in the Union. This quite
> useful when defining optional fields, we just need to define the Field type
> as Union and place the null type in the first index of the type array.
> When parsing an Avro Schema represented in JSON with the Schema.Parser class,
> one has to set the field _default_ to {_}null{_}, even with the type is
> defined as Union and _null_ is in the first index of the type array.
> The Schema.Parser should handle this corner case gracefully and allow
> omitting the default value key for fields with type Union and its first type
> {_}null{_}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)