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
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
Thanks