8000 Avro4sEncodingException · Issue #862 · sksamuel/avro4s · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Avro4sEncodingException #862

New issue

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

Open
HilbertGodel opened this issue Dec 18, 2024 · 1 comment
Open

Avro4sEncodingException #862

HilbertGodel opened this issue Dec 18, 2024 · 1 comment

Comments

@HilbertGodel
Copy link
HilbertGodel commented Dec 18, 2024
case class Foo(a: String, b: String)

 implicit object FooEncoder extends Encoder[Foo] {

   override val schemaFor = SchemaFor[Foo]

   override def encode(foo: Foo): GenericData.Record = {
     val record = new GenericData.Record(schema)
     println(schema.toString())
     record.put("a", foo.a.toUpperCase)
     record.put("b", foo.b.toUpperCase)
     record
   }
 }
 implicit object FooDecoder extends Decoder[Foo] {

   override val schemaFor = SchemaFor[Foo]

   override def decode(value: Any) = {
     val record = value.asInstanceOf[GenericRecord]
     Foo(record.get("a").toString.toLowerCase, record.get("b").toString.toLowerCase)
   }
 }

 val format = RecordFormat[Foo]
 // record is a type that implements both GenericRecord and Specific Record
 val record = format.to(Foo("alpha", "beta"))
 println(record)

Raised Exception: Exception in thread "main" com.sksamuel.avro4s.Avro4sEncodingException: Cannot marshall an instance of Foo(alpha,beta) to a Record (had class class org.apache.avro.generic.GenericData$Record, output was {"a": "ALPHA", "b": "BETA"})

Scala Version: 2.12.19
avro4s Version: 4.1.2

Copy link
stale bot commented Apr 26, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the abandoned label Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant
0