Frage

Hi I am trying to extract a JSON using reflection

import net.liftweb.json._
case class Bike(make: String, price: Int) {
   def this(price: Int) = this("Trek", price)
}

val cls = Class.forName("Bike")
val manifest = Manifest.classType(cls)
val parsedData =net.liftweb.json.JsonParser.parse(json)

JsonParser.parse(""" {"price":350} """).extract[manifest]

however I am getting this error:

not found: type manifest
  JsonParser.parse(""" {"price":350} """).extract[manifest]
                                                   ^

although manifest is from type Manifest

War es hilfreich?

Lösung

You can extract directly into a case class

val json = "the json";

val bike = parse(json).extract[Bike];

JSON parsing is done through reflection.

If the class is a runtime construct, create a TypeInfo instance and pass that to the extract method.

Andere Tipps

There is a variation of the extract() method that might work for you, if you provide it with a TypeInfo instance.

See here: https://github.com/lift/lift/blob/master/framework/lift-base/lift-json/src/main/scala/net/liftweb/json/Extraction.scala#L178

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top