When I override the namespace of a Schema and write it to a string, default values for enum types disappear.
Minimal Working Example
import com.github.avrokotlin.avro4k.Avro
import com.github.avrokotlin.avro4k.AvroEnumDefault
import com.github.avrokotlin.avro4k.AvroNamespace
import com.github.avrokotlin.avro4k.schema.overrideNamespace
import kotlinx.serialization.Serializable
import java.io.File
@Serializable
@AvroEnumDefault("UNKNOWN")
@AvroNamespace("com.example")
enum class EnumWithDefault {
UNKNOWN, A, B
}
@Serializable
data class Wrap(val a: EnumWithDefault)
fun main() {
for (useNamespace in listOf(false, true)) {
var schema = Avro.default.schema(Wrap.serializer())
var name = "schema"
if (useNamespace) {
schema = schema.overrideNamespace("com.example.another_namespace")
name += "_with_namespace"
}
File("$name.json").absoluteFile.let {
println("Writing '${it.path}'...")
it.writeText(schema.toString(true))
}
}
}
Problem Description
When I override the namespace of a
Schema
and write it to a string, default values for enum types disappear.Minimal Working Example
This writes the following two files:
Of course, I would like
schema_with_namespace.json
to also define a default value forEnumWithDefault
.Workarounds
Instead of using
overrideNamespace
, consider annotating your top-level class with@AvroNamespace
.Versions
I defined the following plugin / library versions in my gradle buildscript.