avro4k icon indicating copy to clipboard operation
avro4k copied to clipboard

Value classes not working (feature request ?)

Open Chuckame opened this issue 2 years ago • 4 comments

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 ?" 😄 )

Chuckame avatar Sep 05 '22 17:09 Chuckame