Skip to content

@JsonEnumDefaultValue not supported when using AvroMapper to generate schema from Java class #388

Closed
@Sonic-Rage

Description

@Sonic-Rage
public enum Foobar {
    @JsonEnumDefaultValue
    FOO,
    BAR;
}

produces 
{
  "type" : "enum",
  "name" : "Foobar",
  "namespace" : "foo",
  "symbols" : [ "FOO", "BAR" ]
}

Need it to have the default key value pair in order to make enum forward compatible

{
  "type" : "enum",
  "name" : "FooBar",
  "namespace" : "foo",
  "symbols" : [ "FOO", "BAR" ],
  "default" : "FOO"
}

Unless I'm missing something I can't find a way to configure the class to fill in the default value when creating the schema

Configured the AvroMapper in some groovy to create the schema for reference

      avroMapper.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false)
                    .configure(JsonGenerator.Feature.IGNORE_UNKNOWN, true);
          avroMapper.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)

      AvroSchemaGenerator gen = new AvroSchemaGenerator();
        gen.enableLogicalTypes();
        avroMapper.acceptJsonFormatVisitor(classFile, gen);
        AvroSchema schemaWrapper = gen.getGeneratedSchema();

        org.apache.avro.Schema avroSchema = schemaWrapper.getAvroSchema();
        String avroSchemaInJSON = avroSchema.toString(true);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions