I generated case classes from an Avro schema file using sbt-avrohugger and I want to use avro4s for generating a kafka Serde because io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde doesn't work with classes that include Shapeless classes.
Initially I tried this:
import org.apache.kafka.common.serialization.Serde
import com.sksamuel.avro4s.kafka.GenericSerde
import com.sksamuel.avro4s.BinaryFormat
import scala.collection.JavaConverters._
implicit val inputSerde: Serde[MyClass] = new GenericSerde[MyClass](BinaryFormat)
val serdeConfig = Map("schema.registry.url" -> "SOME_URL").asJava
inputSerde.configure(serdeConfig, false)
MyClass has a lot of nested classes and I got this error during compilation:
[error] Error while emitting MyClass$
[error] Method too large: MyClass$.<init> ()V
Then I tried invoking SchemaFor like this:
import org.apache.kafka.common.serialization.Serde
import com.sksamuel.avro4s.kafka.GenericSerde
import com.sksamuel.avro4s.BinaryFormat
import com.sksamuel.avro4s.SchemaFor
import scala.collection.JavaConverters._
implicit val myClassSchemaFor: SchemaFor[MyClass] = SchemaFor[MyClass]
implicit val inputSerde: Serde[MyClass] = new GenericSerde[MyClass](BinaryFormat)
val serdeConfig = Map("schema.registry.url" -> "SOME_URL").asJava
inputSerde.configure(serdeConfig, false)
But then I got this error during runtime:
[error] caused by java.lang.ExceptionInInitializerError
[error] caused by java.lang.NullPointerException
[error] sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[error] sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
[error] sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
[error] java.lang.reflect.Constructor.newInstance(Constructor.java:423)
....
[error]
[error] CAUSED BY java.lang.ExceptionInInitializerError
[error] com.sksamuel.avro4s.AvroSchema$.apply(AvroSchema.scala:20)
[error] com.sksamuel.avro4s.kafka.GenericSerde.<init>(GenericSerde.scala:21)
...
Hello,
I generated case classes from an Avro schema file using sbt-avrohugger and I want to use avro4s for generating a kafka Serde because
io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
doesn't work with classes that include Shapeless classes.Initially I tried this:
MyClass
has a lot of nested classes and I got this error during compilation:Then I tried invoking
SchemaFor
like this:But then I got this error during runtime:
Any idea how to solve or debug this problem ?
These are the main dependencies:
sbt-avrohugger version 2.8.0 scala version: 2.12.18 Thanks