/ / Scala + Lift: conversiones implícitas ambiguas al analizar XML - xml, scala, lift

Scala + Lift: conversiones implícitas ambiguas al analizar XML: xml, scala, lift

Tengo un método que extrae objetos de acción de un nodo xml:

    private def appendActionsFromXml(device: Device, xml: Node) = {
xml  "actions"  "action" map {
x => {
val key = x  "@key" text
val value = x  "@value" text
device.createAction(key, value)
}
}
}

Sin embargo, como importé import net.liftweb.json.JsonDSL._ en la misma clase, obtengo una ambigüedad cuando extraigo el atributo "@key" de x:

[INFO] Note that implicit conversions are not applicable because they are ambiguous
[INFO]  both method string2jvalue in trait Implicits of type (x: String)net.liftweb.json.JsonAST.JString
[INFO]  and method augmentString in object Predef of type (x: String)scala.collection.immutable.StringOps
[INFO]  are possible conversion functions from String to ?{val apply: ?}
[INFO]  val value = x  "@value" text

¿Cómo resuelvo esta ambigüedad en este método perticular?

Respuestas

0 para la respuesta № 1

Prueba esto:

val key: String = x  "@key" text
val value: String = x  "@value" text

0 para la respuesta № 2

Mueva su importación JsonDSL (o inversamente las importaciones XML) a un alcance más pequeño si es posible.

class A {
def doXmlStuff = { ... }
def doJsonStuff = {
import net.liftweb.json.JsonDSL._
...
}
}

0 para la respuesta № 3

Por lo general, la forma de resolver este tipo de problema es reducir el alcance de la importación. En este caso, tal vez no necesite tener net.liftweb.json.JsonDSL._ en alcance dentro del alcance que encierra appendActionsFromXml. Es difícil decir si eso funcionaría sin ver más contexto.