Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value classes not working (feature request ?) #131

Closed
Chuckame opened this issue Sep 5, 2022 · 5 comments · Fixed by #183
Closed

Value classes not working (feature request ?) #131

Chuckame opened this issue Sep 5, 2022 · 5 comments · Fixed by #183
Labels
enhancement New feature or request

Comments

@Chuckame
Copy link
Contributor

Chuckame commented Sep 5, 2022

Hey,

Is there a way to have value classes ? (previously called inlined classes)

The goal is to wrap primitive types (string, int, in our example) inside a value class, to be used with a primitive avro schema.

error:

Non-serializable class kotlin.String is not supported by class com.github.avrokotlin.avro4k.encoder.RootRecordEncoder encoder

To reproduce:

@JvmInline
@Serializable
value class StringValueClass(val value: String)

val kotlinSerializer = serializer<StringValueClass>() // working well
val avroSchema = Avro.default.schema(kotlinSerializer) // working well, creates a "string" schema
Avro.default.toRecord(kotlinSerializer,avroSchema, StringValueClass("awesome"))

I can help if you want, since this feature should be awesome for handling primitive keys while having a readable code (instead of ask "hey, what's inside the string key ? hexadecimal ? the name ? from whhich other field it comes ?" 😄 )

@thake
Copy link
Member

thake commented Sep 20, 2022

Should be solved together with #80 as both cases require an extension of the RootRecordEncoder. The problem is that primitives are not wrappable in an Avro record. Therefore the API of avro4k needs to change to support this use case. I've not yet had the time to come up with a good API design that supports both the use cases (record and primitives). Feel free to contribute a proposal.

@thake
Copy link
Member

thake commented Sep 20, 2022

Maybe #116 can also be solved together. The API change should be capable of this.

@Chuckame
Copy link
Contributor Author

I begun my work on avro4k to handle primitive types, but as you said, this lib is totally independant from kafka libs. This lib is more an avro encoder, while we need another lib for kafka. I think this lib is not dedicated for this kind of thing, because it will be too much generic. Like a decode func that will returns a T? or Any? that is not type-safe.

Maybe the best is to really have 2 different kafka serializers: one for records, and another for primitives. I'll create a PR if needed on your other avro4k-kafka-serializer lib

@Chuckame Chuckame reopened this Sep 4, 2023
@Chuckame Chuckame added the enhancement New feature or request label Sep 4, 2023
@Chuckame Chuckame mentioned this issue Jan 22, 2024
14 tasks
@Chuckame
Copy link
Contributor Author

I just discovered that AvroFixed can be put on a value class as the documentation say. Since the value classes would be natively handled, then this annotation should just be possible on properties.

@Chuckame
Copy link
Contributor Author

Done in #183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants