Skip to content

ClassCastException on deserializing case class with field @AvroTransient and default value #903

Description

@minosiants

Guys,

I'm trying to serialise and deserialise data using case class with @AvroTransient field and default value. I Assumed that default value should be used but I got this exception during deserialisation.

java.lang.ClassCastException: class scala.None$ cannot be cast to class scala.collection.immutable.List (scala.None$ and scala.collection.immutable.List are in unnamed module of loader 'app')
Is there restriction that field should be option ?
Is there way to make it work ?

here is the code https://scastie.scala-lang.org/5fbq6uV1Q1eSCXnXFdSQEw

import java.io.{
  BufferedOutputStream,
  ByteArrayInputStream,
  ByteArrayOutputStream,
  File
}
import com.sksamuel.avro4s.*
case class Car(name: String, @AvroTransient key: List[String] = List.empty)
val t = Car("helo")
val schema = AvroSchema[Car]
val baos = new ByteArrayOutputStream()
val os = AvroOutputStream.binary[Car].to(baos).build()
os.write(Seq(t))
os.flush()
os.close()
val bais = new ByteArrayInputStream(baos.toByteArray)
val is = AvroInputStream.binary[Car].from(bais).build(schema)
val cars = is.iterator.toSet
is.close()

println(cars.mkString("\n"))

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions