feat!: No more reflection and customizable logical types #175
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 ifdescriptor 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)