我正在使用avro4s
https://github.com/sksamuel/avro4s
我写了这段代码
import java.io.ByteArrayOutputStream
import com.sksamuel.avro4s._
sealed trait Dibble
case class Dobble(str: String) extends Dibble
case class Dabble(dbl: Double) extends Dibble
case class Drapper(dibble: Dibble)
val drapperIn = Drapper(Dabble(2.0))
val bios = new ByteArrayOutputStream
val avro = AvroOutputStream.binary[Drapper](bios)
avro.write(drapperIn)
avro.close()
val is = AvroInputStream.binary[Drapper](bios.toByteArray)
val drapperOut = is.iterator().toList.head
is.close()
println(drapperIn == drapperOut)
但是读取二进制数据时出现以下错误
错误:(18, 47) 找不到类型为 com.sksamuel.avro4s.FromRecord[A$A449.this.Drapper] 的证据参数的隐式值,惰性值 = AvroInputStream.binaryDrapper ^ 错误:(18, 47) 不够方法二进制的参数:(隐含证据$13:com.sksamuel.avro4s.SchemaFor[A$A449.this.Drapper],隐含证据$14:com.sksamuel.avro4s.FromRecord[A$A449.this.Drapper])com。 sksamuel.avro4s.AvroBinaryInputStream[A$A449.this.Drapper]。未指定值参数证据 $14。惰性值是 = AvroInputStream.binaryDrapper ^