根据activator-akka-cassandra示例,我创建了自己的应用程序,将数据保存到cassandra。
我将数据模型定义如下
import play.api.libs.json.Json
case class Location(lat: Double, long: Double)
object Location {
implicit def toLocation(lat: Double, long: Double) = Location(lat, long)
}
case class LocationWithTime(location: Location, time: Long)
object LocationWithTime {
implicit def toLocationWithTime(location: Location, time: Long) = LocationWithTime(location, time)
}
case class Ping(pingUuid: String, senPhoneNumber: String, recPhoneNumber: Set[String], locationWithTime: LocationWithTime)
object Ping {
implicit val LocationFormat = Json.format[Location]
implicit val LocationWithTimeFormat = Json.format[LocationWithTime]
implicit val PingFormat = Json.format[Ping]
}
不幸的是应该保存数据的代码:
def insertPing(ping: Ping): Unit =
session.executeAsync(insertPing.bind(ping.pingUuid, ping.senPhoneNumber, ping.recPhoneNumber,
ping.locationWithTime.location.lat, ping.locationWithTime.location.long, ping.locationWithTime.time))
不编译并返回错误
Error:(24, 38) the result type of an implicit conversion must be more specific than AnyRef
ping.locationWithTime.location.lat, ping.locationWithTime.location.long, ping.locationWithTime.time))
^
example data model中的案例类扩展了AnyVal。基于this我会猜测在我的情况下类似的东西也可以做到,但是我不能这样做,因为ValueClasses只能有一个参数。 我该如何解决这个问题?
答案 0 :(得分:5)
虽然我不熟悉Cassandra,但我认为你的问题是bind
需要Java Object
s(即AnyRef
s)和lat
,是{ {1}}(即Java scala.Double
),不是double
。
您可以将AnyRef
包裹在scala.Double
中来实现。
java.lang.Double