avro-kotlin / avro4k

Avro format support for Kotlin
Apache License 2.0
188 stars 36 forks source link

[schema] Logical types generated in nested field #169

Closed Chuckame closed 5 months ago

Chuckame commented 9 months 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 5 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.