有了这个代码经与隐式转换的麻烦斯卡拉
case class Workspace(ident: Long, name: String)
case class Project(ident: Long, name: String)
implicit def workspaceJSON: JSONR[Workspace] = new JSONR[Workspace] {
def read(json: JValue) =
Workspace.applyJSON(field[Long]("id"), field[String]("name"))(json)
}
implicit def projectJSON: JSONR[Project] = new JSONR[Project] {
def read(json: JValue) =
Project.applyJSON(field[Long]("id"), field[String]("name"))(json)
}
def parseEnt[T: JSONR](json: JValue): Either[String, T] =
fromJSON[T](json).toEither.left.map{ _.toString }
def fetchProjects(ws: Workspace): Either[String, Project] = {
parseEnt(parse("some text"))
}
从而未能在parseEnt(parse("some text"))
编译
ambiguous implicit values: both method taskJSON in class Fetcher of type =>
Fetcher.this.JSONR[types.Task] and method workspaceJSON in class Fetcher of type =>
Fetcher.this.JSONR[Fetcher.this.Workspace] match expected type Fetcher.this.JSONR[T]
有没有一种方法,以确保阶,在这种情况下,我想类型变量T
将成为Project
并选择projectJSON
函数来解析它?或者如果我做错了,那么它是如何以正确的方式呢?
如果您明确说出您期望解析的内容,那么该怎么办? parseEnt [Project](解析(“一些文本”)) – johanandren
谢谢你,帮助。 – cvb