Skip to content

AvroSchemaGenerator: logicalType(s) never set for non-date classes #535

Description

@credmond

logicalTypes doesn't appear to be set for anything other than dates.

    public static void main(String[] args) throws Exception {
        // Create AvroMapper and AvroSchemaGenerator
        AvroMapper avroMapper = AvroMapper.builder().addModule(new AvroJavaTimeModule()).build();

        AvroSchemaGenerator schemaGen = new AvroSchemaGenerator();
        schemaGen.enableLogicalTypes(); // Enable logical types

        // Configure AvroMapper with the generator
        avroMapper.acceptJsonFormatVisitor(MyClass.class, schemaGen);

        // Get the generated schema
        Schema schema = schemaGen.getGeneratedSchema().getAvroSchema();

        // Print the schema
        System.out.println(schema.toString(true));
    }

Output:

{
  "type" : "record",
  "name" : "MyClass",
  "namespace" : "com.fasterxml.jackson.dataformat.avro.jsr310",
  "fields" : [ {
    "name" : "someBigDecimal",
    "type" : [ "null", {
      "type" : "string",
      "java-class" : "java.math.BigDecimal"
    } ]
  }, {
    "name" : "someDouble",
    "type" : {
      "type" : "double",
      "java-class" : "java.lang.Double"
    }
  }, {
    "name" : "someDoubleObject",
    "type" : [ "null", {
      "type" : "double",
      "java-class" : "java.lang.Double"
    } ]
  }, {
    "name" : "timestamp",
    "type" : [ "null", {
      "type" : "long",
      "logicalType" : "timestamp-millis"
    } ]
  } ]
}

MyClass:

public class MyClass {
    private Instant timestamp;
    private double someDouble;
    private Double someDoubleObject;
    private BigDecimal someBigDecimal;

    // Setters / getters
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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