尽管声明了隐式类型编译错误
Implicit type compilation error although declared
使用 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
}
我收到以下错误:
"No org.json4s.Formats found. Try to bring an instance of
org.json4s.Formats in scope or use the org.json4s.DefaultFormats."
你使用了错误的隐式。您需要使用 DefaultFormats
而不是 DefaultJsonFormats
:
implicit val formats = org.json4s.DefaultFormats
使用 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
}
我收到以下错误:
"No org.json4s.Formats found. Try to bring an instance of org.json4s.Formats in scope or use the org.json4s.DefaultFormats."
你使用了错误的隐式。您需要使用 DefaultFormats
而不是 DefaultJsonFormats
:
implicit val formats = org.json4s.DefaultFormats