scala - JSON deserialization using reflection -
hi trying extract 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 getting error:
not found: type manifest jsonparser.parse(""" {"price":350} """).extract[manifest] ^ although manifest type manifest
you can extract directly case class
val json = "the json"; val bike = parse(json).extract[bike]; json parsing done through reflection.
if class runtime construct, create typeinfo instance , pass extract method.
Comments
Post a Comment