【问题标题】:Implicit type compilation error although declared尽管声明了隐式类型编译错误
【发布时间】:2016-02-25 13:21:18
【问题描述】:

使用 org.json4s,我正在尝试编译这段代码:

implicit val formats = org.json4s.DefaultJsonFormats
for {
  parsed <- Try(parse(message)).toOption
  purchase <- parsed.extractOpt[Item]
} yield {
  val datetime = new DateTime(purchase.time)
  val roundedTime = datetime.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)
  Key(purchase.item_id, roundedTime) -> purchase.amount
}   

我收到以下错误:

“没有找到org.json4s.Formats。尝试带一个实例 org.json4s.Formats 范围内或使用 org.json4s.DefaultFormats。"

【问题讨论】:

    标签: scala scalatest json4s


    【解决方案1】:

    您使用了错误的隐式。您需要使用DefaultFormats 而不是DefaultJsonFormats

    implicit val formats = org.json4s.DefaultFormats
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-12
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多