toolisticon / avro-kotlin

Opionionated set of extension functions and helpers for using Apache Avro with Kotlin
https://avro-kotlin.toolisticon.io/stable/
Apache License 2.0
3 stars 0 forks source link

Deserialization of Logical Types doesn't work correctly #83

Closed zambrovski closed 2 months ago

zambrovski commented 2 months ago

Steps to reproduce

  @Test
  fun `serialize data class with uuid customerId and money to record and single object encoded and back`() {
    val amount = Money.of(10, "EUR")
    val accountId = UUID.randomUUID()
    val customerId = CustomerId.random()

    val event = BankAccountCreatedData(accountId, customerId, amount)
    val resolver = avroSchemaResolver(KotlinExample.avro.schema(BankAccountCreatedData::class))

    val record = KotlinExample.avro.toRecord(event)

    assertThat(KotlinExample.avro.fromRecord(record, BankAccountCreatedData::class)).isEqualTo(event)

    // go down and run through SOE

    val singleObjectEncodedBytes = GenericRecordCodec.encodeSingleObject(record)
    val recordDecodedFromBytes = GenericRecordCodec.decodeSingleObject(singleObjectEncodedBytes, resolver.invoke())
    val deserializedEvent = AvroKotlinSerialization().fromRecord<BankAccountCreatedData>(recordDecodedFromBytes)
    assertThat(deserializedEvent).isEqualTo(event)
  }

Expected behaviour

Attempt to convert already converted logical type just returns it.

Actual behaviour

Exception...

jangalinski commented 2 months ago

checking ...