Not getting values

20 views
Skip to first unread message

Nandish Nagaraj

unread,
Feb 9, 2018, 11:39:37 AM2/9/18
to Lift
import net.liftweb.json.DefaultFormats
import net.liftweb.json._

class DQJsonHandler {

}

object DQJsonHandler{
implicit val formats = DefaultFormats
val dqjson = """{
"DQMap":
[{
"entitytype":{"entityURI": "MedicinalProduct"
}
}]
}
"""
def main(args: Array[String]): Unit = {

case class DQMap(entity:Seq[EntityType])

case class EntityType(entityURI: Option[String])


val json = parse(dqjson)
println(json)


val entityelements = (json \\ "entitytype").children
println(entityelements)
for ( element <- entityelements ) {
println("-------"+element)
val e = element.extract[EntityType]
println(e.entityURI.toString)
}


}
}



Below is the output as None


JObject(List(JField(DQMap,JArray(List(JObject(List(JField(entitytype,JObject(List(JField(entityURI,JString(MedicinalProduct))))))))))))
List(JField(entityURI,JString(MedicinalProduct)))
-------JField(entityURI,JString(MedicinalProduct))
None



Antonio Salazar Cardozo

unread,
Feb 23, 2018, 12:43:31 PM2/23/18
to Lift
You'll note `entity` here is a JField; JField's can't be extracted directly. You want to
extract the field's value:

for (JField(_, element) <- entityelements) {
  val e = element.extract[EntityType]
}

Give that a shot, I think it should work.
Thanks,
Antonio
Reply all
Reply to author
Forward
0 new messages