Search code examples
javaavro

Execution default of goal org.apache.avro:avro-maven-plugin:1 .10.2:schema failed: Invalid default for field


During the execution of avro-maven-plugin:schema goal I keep getting this error:

[ERROR] Failed to execute goal org.apache.avro:avro-maven-plugin:1.10.2:schema (default) on project test: Execution default of goal org.apache.avro:avro-maven-plugin:1
.10.2:schema failed: Invalid default for field someId: null not a ["int","null"] -> [Help 1]

and this is how the field looks like in the schema:

{
    "name" : "someId",
    "type" : [ "int", "null" ],
    "default" : null
}

and the schema is valid according to https://json-schema-validator.herokuapp.com/avro.jsp.

Does anyone know what's wrong and how to fix?

Thanks in advance...


Solution

  • The specification states that the default value must match the first element of the union: https://avro.apache.org/docs/current/spec.html#Unions.

    Therefore you need to change the order of your union to have the null type first, or change the default to be an integer type.