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
Open
Open
@HilbertGodel

Description

@HilbertGodel
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 = n
5505
ew 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0