2017-07-24 60 views
1

我試圖開始與avro & avro4s,我遇到了麻煩得到一個愚蠢的例子工作。找不到隱含的值FromRecord

我甚至不能讓我自己在源回購發現編譯一個測試版本 - 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。我究竟做錯了什麼?

+0

我能夠用我的avro4s實際域對象序列化,它只是一個問題的反序列化。 – Jason

回答

0

移動的情況下類聲明的方法定義之外:

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) 
    } 
    } 
} 
+1

這是爲什麼? – Jason

相關問題