avro-kotlin / avro4k

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

Allow non-string while string-able values as map keys #114

Closed acruise closed 5 months ago

acruise commented 3 years ago

Hey folks, this library looks pretty good so far, but I'm running into one awkwardness around Map properties keyed by something other than String.

When the key type is a data class in my own codebase, I can annotate it with a serializer with a primitive descriptor, and avro4k is happy to use that. But for an external type, I'd like to be able to have properties like Map<@Contextual SomethingExternal, Foo> and have avro4k look up the serializer for SomethingExternal dynamically from context, but it doesn't seem to do so.

I can set @file:UseSerializers on the file, but I'd rather use @Contextual. Thanks!

vladimirfx commented 3 years ago

Provide a simple example - I try to fix this.

thake commented 3 years ago

@acruise thanks for raising this issue. Can you provide a small code (i.e. a failing unit test) so we can work on a solution more easily?

Chuckame commented 1 year ago

Just a side note. Regarding performances, you should use @useserializer instead of contextual, because contextual is resolving the serializer at runtime, while @useserializer is resolved at compile time!

Chuckame commented 1 year ago

See https://github.com/avro-kotlin/avro4k/issues/148

Chuckame commented 5 months ago

Done in #183