我正在尝试使用avro & avro4s,但在运行一个愚蠢的示例时遇到了麻烦。
我甚至不能在源代码库中找到自己的测试版本来编译- https://github.com/sksamuel/avro4s/blob/master/avro4s-core/src/test/scala/com/sksamuel/avro4s/AvroJsonInputTest.scala#L14-L20
我得到了标题could not find implicit value for parameter fromRecord: com.sksamuel.avro4s.FromRecord[Foo]中提到的错误。
package test
import java.io.ByteArrayInputStream
import com.sksamuel.avro4s._
import org.specs2.mutable.Specification
class AvroSpec extends Specification {
"My classes" should {
"be deserialized by avro" in {
case class Foo(num: Int, name: String)
val json = """{ "num": 17, "name": "jibba-jabbba" }"""
val inst = Foo(num = 17, name = "jibba-jabba")
val in = new ByteArrayInputStream(json.getBytes("UTF-8"), 0, json.length)
val foo = new AvroJsonInputStream[Foo](in).iterator.toSet
in.close()
foo mustEqual Set(inst)
}
}
}我使用的是Scala 2.11.8和avro 1.7.0。我做错了什么?
发布于 2017-07-24 19:54:15
将case类声明移到方法定义之外:
package test
import java.io.ByteArrayInputStream
import com.sksamuel.avro4s._
import org.specs2.mutable.Specification
case class Foo(num: Int, name: String)
class AvroSpec extends Specification {
"My classes" should {
"be deserialized by avro" in {
val json = """{ "num": 17, "name": "jibba-jabbba" }"""
val inst = Foo(num = 17, name = "jibba-jabba")
val in = new ByteArrayInputStream(json.getBytes("UTF-8"), 0, json.length)
val foo = new AvroJsonInputStream[Foo](in).iterator.toSet
in.close()
foo mustEqual Set(inst)
}
}
}https://stackoverflow.com/questions/45276413
复制相似问题