diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/annotations.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/annotations.kt index d0442f68..fdee54ea 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/annotations.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/annotations.kt @@ -23,26 +23,16 @@ annotation class AvroNamespaceOverride( ) /** - * Adds a property to the Avro schema or field. + * Adds a property to the Avro schema or field. Its value could be any valid JSON or just a string. * * Ignored in inline classes. */ @SerialInfo @Repeatable @Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) -annotation class AvroProp(val key: String, val value: String) - -/** - * Adds a json property to the Avro schema or field. - * - * Ignored in inline classes. - */ -@SerialInfo -@Repeatable -@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) -annotation class AvroJsonProp( +annotation class AvroProp( val key: String, - @Language("JSON") val jsonValue: String, + @Language("JSON") val value: String, ) /** diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/ClassVisitor.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/ClassVisitor.kt index 82f2ac8f..65b44511 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/ClassVisitor.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/ClassVisitor.kt @@ -33,8 +33,7 @@ internal class ClassVisitor( false ) annotations.aliases?.value?.forEach { schema.addAlias(it) } - annotations.props.forEach { schema.addProp(it.key, it.value) } - annotations.jsonProps.forEach { schema.addProp(it.key, it.jsonNode) } + annotations.props.forEach { schema.addProp(it.key, it.jsonNode) } schema } this.schemaAlreadyResolved = schemaAlreadyResolved @@ -105,8 +104,7 @@ internal class ClassVisitor( fieldDefault ) annotations.aliases.flatMap { it.value.asSequence() }.forEach { field.addAlias(it) } - annotations.props.forEach { field.addProp(it.key, it.value) } - annotations.jsonProps.forEach { field.addProp(it.key, it.jsonNode) } + annotations.props.forEach { field.addProp(it.key, it.jsonNode) } return field } diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/ValueVisitor.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/ValueVisitor.kt index 05db8322..685b9e14 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/ValueVisitor.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/ValueVisitor.kt @@ -48,8 +48,7 @@ internal class ValueVisitor internal constructor( .symbols(*descriptor.elementNamesArray) annotations.aliases?.value?.forEach { schema.addAlias(it) } - annotations.props.forEach { schema.addProp(it.key, it.value) } - annotations.jsonProps.forEach { schema.addProp(it.key, it.jsonNode) } + annotations.props.forEach { schema.addProp(it.key, it.jsonNode) } setSchema(schema) } diff --git a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/VisitorContext.kt b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/VisitorContext.kt index c83efa72..713de3cb 100644 --- a/src/main/kotlin/com/github/avrokotlin/avro4k/schema/VisitorContext.kt +++ b/src/main/kotlin/com/github/avrokotlin/avro4k/schema/VisitorContext.kt @@ -10,7 +10,6 @@ import com.github.avrokotlin.avro4k.AvroDefault import com.github.avrokotlin.avro4k.AvroDoc import com.github.avrokotlin.avro4k.AvroEnumDefault import com.github.avrokotlin.avro4k.AvroFixed -import com.github.avrokotlin.avro4k.AvroJsonProp import com.github.avrokotlin.avro4k.AvroLogicalType import com.github.avrokotlin.avro4k.AvroNamespaceOverride import com.github.avrokotlin.avro4k.AvroProp @@ -57,7 +56,6 @@ internal data class InlineClassFieldAnnotations( */ internal data class FieldAnnotations( val props: Sequence, - val jsonProps: Sequence, val aliases: Sequence, val doc: AvroDoc?, val default: AvroDefault?, @@ -65,7 +63,6 @@ internal data class FieldAnnotations( ) { constructor(descriptor: SerialDescriptor, elementIndex: Int) : this( descriptor.findElementAnnotations(elementIndex).asSequence(), - descriptor.findElementAnnotations(elementIndex).asSequence(), descriptor.findElementAnnotations(elementIndex).asSequence(), descriptor.findElementAnnotation(elementIndex), descriptor.findElementAnnotation(elementIndex), @@ -127,14 +124,12 @@ internal data class SimpleAnnotatedLocation( */ internal data class TypeAnnotations( val props: Sequence, - val jsonProps: Sequence, val aliases: AvroAlias?, val doc: AvroDoc?, val enumDefault: AvroEnumDefault?, ) { constructor(descriptor: SerialDescriptor) : this( descriptor.findAnnotations().asSequence(), - descriptor.findAnnotations().asSequence(), descriptor.findAnnotation(), descriptor.findAnnotation(), descriptor.findAnnotation() @@ -163,12 +158,12 @@ internal fun ValueAnnotations?.appendAnnotations(other: ValueAnnotations) = private val objectMapper = ObjectMapper() -internal val AvroJsonProp.jsonNode: JsonNode +internal val AvroProp.jsonNode: JsonNode get() { - if (jsonValue.isStartingAsJson()) { - return objectMapper.readTree(jsonValue) + if (value.isStartingAsJson()) { + return objectMapper.readTree(value) } - return TextNode.valueOf(jsonValue) + return TextNode.valueOf(value) } internal val AvroDefault.jsonValue: Any diff --git a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroPropsSchemaTest.kt b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroPropsSchemaTest.kt index b644e3cb..be12c221 100644 --- a/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroPropsSchemaTest.kt +++ b/src/test/kotlin/com/github/avrokotlin/avro4k/schema/AvroPropsSchemaTest.kt @@ -2,7 +2,6 @@ package com.github.avrokotlin.avro4k.schema import com.github.avrokotlin.avro4k.AvroAssertions import com.github.avrokotlin.avro4k.AvroEnumDefault -import com.github.avrokotlin.avro4k.AvroJsonProp import com.github.avrokotlin.avro4k.AvroProp import io.kotest.core.spec.style.StringSpec import kotlinx.serialization.Serializable @@ -16,11 +15,12 @@ class AvroPropsSchemaTest : StringSpec({ }) { @Serializable @AvroProp("hey", "there") - @AvroJsonProp("counting", """["one", "two"]""") + @AvroProp("counting", """["one", "two"]""") private data class TypeAnnotated( - @AvroJsonProp( + @AvroProp("cold", "play") + @AvroProp( key = "complexObject", - jsonValue = """{ + value = """{ "a": "foo", "b": 200, "c": true, @@ -29,14 +29,13 @@ class AvroPropsSchemaTest : StringSpec({ "f": ["bar", 404, false, null, {}] }""" ) - @AvroProp("cold", "play") val field: EnumAnnotated, ) @Serializable @AvroEnumDefault("Green") @AvroProp("enums", "power") - @AvroJsonProp("countingAgain", """["three", "four"]""") + @AvroProp("countingAgain", """["three", "four"]""") private enum class EnumAnnotated { Red, Green,