avro-kotlin / avro4k

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

Recursive classes are not supported #77

Closed geomagilles closed 3 years ago

geomagilles commented 3 years ago

For Example:

@Serializable
data class User(
    val child: User?
)

Can be serialized using Json:

val msg = User(User(null))
println(Json.encodeToString(msg)) // {"child":{"child":null}}

But failed to be serialized using Avro

Avro.default.encodeToByteArray(User.serializer(), msg) 

throws a stackoverflow of numerous:

    at com.sksamuel.avro4k.schema.ClassSchemaFor.buildField(ClassSchemaFor.kt:70)
    at com.sksamuel.avro4k.schema.ClassSchemaFor.dataClassSchema(ClassSchemaFor.kt:55)
    at com.sksamuel.avro4k.schema.ClassSchemaFor.schema(ClassSchemaFor.kt:43)
    at com.sksamuel.avro4k.schema.NullableSchemaFor.schema(SchemaFor.kt:123)
thake commented 3 years ago

@geomagilles Thanks for reporting the issue. This is actually a duplicate of #37 which was incorrectly closed as "won't fix". Closing this issue as a duplicate.