avro-kotlin / avro4k

Avro format support for Kotlin
Apache License 2.0
198 stars 37 forks source link

[schema] Logical types generated in nested field #169

Closed Chuckame closed 10 months ago

Chuckame commented 1 year ago

When using the UUIDSerializer for UUID fields, the logicalType is generated as following:

                {
                    "type": "record",
                    "name": "MyClass",
                    "fields": [
                         {
                              "name": "id",
                              "type": {
                                    "type": "string",
                                    "logicalType": "uuid"
                              }
                         }
                    ]
                }

But regarding the avro spec, this nesting seems useless as some examples are shown for decimals and dates, so we should have instead:

                {
                    "type": "record",
                    "name": "MyClass",
                    "fields": [
                        {
                            "name": "id",
                            "type": "string",
                            "logicalType": "uuid"
                        }
                    ]
                }

Same for dates using InstantSerializer where it is also nested:

        {
            "name": "date",
            "type": {
                "type": "long",
                "logicalType": "timestamp-millis"
            }
        },
Chuckame commented 10 months ago

It's wrong, spec is not clear, but for "complex" types (when other fields needed like logicalType or array's item), it must be wrapped inside an object.