avro-kotlin / avro4k

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

feat!: No more reflection and customizable logical types #175

Closed Chuckame closed 5 months ago

Chuckame commented 5 months ago

To remove the reflection needs, I needed to work on the root problem: AvroDescriptor. This feature seems nice, but because of kotlinx serialization plugin, when a field is nullable, then the descriptor is wrapped into a kotlinx-internal class so the AvroDescriptor is not accessible anymore (e.g. we cannot check if descriptor is AvroDescriptor as the avro descriptor is inside a private field now).

Now how to generate custom schemas for logical types without being able of creating custom descriptors ? Just by adding annotations to the descriptor.

Then when we want to generate a schema, we first look at our custom annotations AvroXxxLogicalType and depending on the type (time, uuid, decimal, ...), we generate the according schema.

Finally we end up with the same features, without non-standard workarounds, and with much better performances as there isn't reflection anymore!

Relates to #148

Closes #147

Breaking changes

No more AvroDescriptor. If we really want to keep having an api to access custom schema generation (is it really used ?!), then we could create a new annotation to give the custom schema generator (KISS, really wanting it ??) like @CustomSchema(MySchemaGenerator::class)