2015-01-11 51 views
0

我想這個簡單的例子,從淘金者快速入門:Argonaut casecodec3?

case class Address(street: String, number: Int, postcode: Int) 

object Address { 
    // Define codecs easily from case classes 
    implicit def AddressCodecJson: CodecJson[Address] = 
    casecodec3(Address.apply, Address.unapply)("street", "number", "post_code") 
} 

我在casecodec3得到一個編譯錯誤。我克隆了argonaut和scalaz repos,並且清理了源代碼,我只能在示例代碼中看到它。這個符號來自哪裏,爲什麼我不能使用它?

回答

1

如果進口都是爲了那麼這應該只是工作:

import argonaut._, Argonaut._ 
case class Address(street: String, number: Int, postcode: Int) 

object Address { 
    implicit def AddressCodecJson: CodecJson[Address] = 
    casecodec3(Address.apply, Address.unapply)("street", "number", "post_code") 
} 

在REPL確保進入粘貼模式

scala> :paste 
// Entering paste mode (ctrl-D to finish) 

import argonaut._, Argonaut._ 
case class Address(street: String, number: Int, postcode: Int) 

object Address { 
    implicit def AddressCodecJson: CodecJson[Address] = 
    casecodec3(Address.apply, Address.unapply)("street", "number", "post_code") 
} 

// Exiting paste mode, now interpreting. 

defined class Address 
defined object Address 

你看不到源在github上,因爲源生成例如GeneratedCodecJsons.scala在此處構建的定義 https://github.com/argonaut-io/argonaut/blob/master/project/Boilerplate.scala

+0

謝謝!我定義了一個名爲'Argonaut'的自定義單例對象,它引入了導致問題的名稱衝突。 – clay

相關問題