I am trying to generate Avro4s's RecordFormat in reflection based on class path. The following code throws an error.
case class MyCaseClass(a: Int)
println(toolBox.compile {
toolBox.parse(
s"""
|import com.sksamuel.avro4s._
|import mypackage.MyCaseClass
|RecordFormat[MyCaseClass]
|""".stripMargin
)
}())
could not find implicit value for evidence parameter of type com.sksamuel.avro4s.Decoder[mypackage.MyCaseClass]
RecordFormat is like
object RecordFormat {
def apply[T <: Product : Encoder : Decoder : SchemaFor]: RecordFormat[T] = apply(AvroSchema[T])
}
I can see, it can resolve Encoder[MyCaseClass]
and SchemaFor[MyCaseClass]
but fails for Decoder[MyCaseClass]
.
The same code can resolve RecordFormat[MyCaseClass]
without reflection.
I can see that Decoder
is implemented with macro similar to Encoder
.
implicit def applyMacro[T <: Product]: Decoder[T] = macro applyMacroImpl[T]
Why reflection cannot resolve the implicit evidence?
Aucun commentaire:
Enregistrer un commentaire