We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider this example:
//> using scala 3.3.5 //> using dep com.sksamuel.avro4s::avro4s-core:5.0.14 import com.sksamuel.avro4s.* import java.io.{ByteArrayInputStream, ByteArrayOutputStream} import scala.util.{Using, Try} sealed trait ExampleWithSealed derives Decoder, Encoder, SchemaFor object ExampleWithSealed { case class Foo(value: String) extends ExampleWithSealed case object Bar extends ExampleWithSealed } enum ExampleWithEnum derives Decoder, Encoder, SchemaFor { case Foo(value: String) case Bar } import java.io.{ByteArrayInputStream, ByteArrayOutputStream} def roundTrip[A: Decoder: Encoder: SchemaFor](value: A): Try[A] = { for { encoded <- Using(new ByteArrayOutputStream()) { baos => val aos = AvroOutputStream.json[A].to(baos).build() aos.write(value) aos.close() aos.flush() baos.toByteArray } decoded <- Using(new ByteArrayInputStream(encoded)) { bais => AvroInputStream .json[A] .from(bais) .build(SchemaFor[A].schema) .asInstanceOf[AvroJsonInputStream[A]] .singleEntity }.flatten } yield decoded } println(roundTrip[ExampleWithSealed](ExampleWithSealed.Foo("example"))) println(roundTrip[ExampleWithEnum](ExampleWithEnum.Foo("example")))
I'd expect both println to show exactly the same behavior. Meanwhile, it produces:
Success(Foo(example)) Failure(java.lang.IllegalArgumentException: requirement failed)
Changing Scala from 3.3.5 to 3.6.3 doesn't change the result.
Removing derives and using automatic derivation, doesn't change it either.
derives
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Consider this example:
I'd expect both println to show exactly the same behavior. Meanwhile, it produces:
Changing Scala from 3.3.5 to 3.6.3 doesn't change the result.
Removing
derives
and using automatic derivation, doesn't change it either.The text was updated successfully, but these errors were encountered: