You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Michael Nielson (Jira)" <ji...@apache.org> on 2020/07/02 19:36:00 UTC

[jira] [Created] (AVRO-2879) Builder.build fails when enum has a default value

Michael Nielson created AVRO-2879:
-------------------------------------

             Summary: Builder.build fails when enum has a default value
                 Key: AVRO-2879
                 URL: https://issues.apache.org/jira/browse/AVRO-2879
             Project: Apache Avro
          Issue Type: Bug
          Components: java
            Reporter: Michael Nielson


I would expect this schema to allow building an Avro Issue without providing a value for severity but it fails:
{code:json}
{
  "protocol" : "Protocol",
  "namespace" : "com.namespace",
  "types" : [ {
    "type" : "record",
    "name" : "Issue",
    "fields" : [ {
      "name" : "id",
      "type" : "string"
    }, {
      "name" : "severity",
      "type" : {
        "type" : "enum",
        "name" : "Severity",
        "symbols" : [ "Unknown", "Mild", "Moderate", "Severe" ],
        "default" : "Unknown"
      }
    } ]
  } ],
  "messages" : { }
}
{code}
{code:java}
Issue.newBuilder().setId("someId").build();
{code}
Error:
{noformat}
Field severity type:ENUM pos:4 not set and has no default value
Path in schema: --> severity
	at org.apache.avro.generic.GenericData.getDefaultValue(GenericData.java:1173)
	at org.apache.avro.data.RecordBuilderBase.defaultValue(RecordBuilderBase.java:142)
{noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)