You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: