diff --git a/modules/events-processor/src/main/kotlin/dev/adamko/kafkatorio/processor/main.kt b/modules/events-processor/src/main/kotlin/dev/adamko/kafkatorio/processor/main.kt index 6aed9b3..a6b5ff1 100644 --- a/modules/events-processor/src/main/kotlin/dev/adamko/kafkatorio/processor/main.kt +++ b/modules/events-processor/src/main/kotlin/dev/adamko/kafkatorio/processor/main.kt @@ -21,7 +21,8 @@ import org.http4k.format.ConfigurableKotlinxSerialization import org.http4k.format.asConfigurable import org.http4k.format.withStandardMappings -object KSX : ConfigurableKotlinxSerialization({ + +object KXS : ConfigurableKotlinxSerialization({ ignoreUnknownKeys = true prettyPrint = true prettyPrintIndent = " " @@ -37,7 +38,6 @@ object JsonSerdes : Serde> { override fun deserializer() = Deserializer> { _, bytes -> jsonMapper.decodeFromString(bytes.decodeToString()) } - } fun main() { @@ -53,7 +53,7 @@ fun main() { .mapValues { readOnlyKey, value -> println("Mapping $readOnlyKey:$value") jsonMapper.decodeFromString>(value) -// KSX.asA>(value) +// KXS.asA>(value) } .to( { key, value, recordContext -> value.data.objectName }, @@ -63,7 +63,6 @@ fun main() { val topology = builder.build() val properties = appProps.kafkaConfig - val streams = KafkaStreams(topology, properties) streams.setUncaughtExceptionHandler(StreamsExceptionHandler()) diff --git a/modules/events-schema/src/main/kotlin/dev/adamko/kafkatorio/events/schema/factorioEvents.kt b/modules/events-schema/src/main/kotlin/dev/adamko/kafkatorio/events/schema/factorioEvents.kt index 609f90e..6e32078 100644 --- a/modules/events-schema/src/main/kotlin/dev/adamko/kafkatorio/events/schema/factorioEvents.kt +++ b/modules/events-schema/src/main/kotlin/dev/adamko/kafkatorio/events/schema/factorioEvents.kt @@ -1,11 +1,9 @@ package dev.adamko.kafkatorio.events.schema -import kotlin.reflect.full.findAnnotation -import kotlin.reflect.full.findAnnotations +import kotlin.reflect.full.starProjectedType import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -import kotlinx.serialization.Transient import kotlinx.serialization.json.JsonClassDiscriminator @@ -34,14 +32,20 @@ const val FactorioObjectDataDiscriminatorKey: String = "object_name" @Serializable @JsonClassDiscriminator(FactorioObjectDataDiscriminatorKey) -sealed class FactorioObjectData private constructor() { +sealed class FactorioObjectData { // workaround - https://github.com/Kotlin/kotlinx.serialization/issues/1664 - val objectName : String by lazy { - requireNotNull(this::class.findAnnotation()?.value) { - "Couldn't find @SerialName for ${this::class}!" - } + val objectName: String by lazy { + kotlinx.serialization.serializer(this::class.starProjectedType).descriptor.serialName } + + // alternative: find the @SerialName annotation + // Again it must be delegated so there's no backing field and kxs ignores it +// val objectNameByAnnotation: String by lazy { +// requireNotNull(this::class.findAnnotation()?.value) { +// "Couldn't find @SerialName for ${this::class}!" +// } +// } } @Serializable