- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 149
 
Closed
Description
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
}