Scala code:
import net.liftweb.json._
case class Province(id: String, name: String, parentName: Option[String], parentId: Option[String])
case class ProvinceJson(provinceData: List[Province])
object Test extends Application {
val json = """ {
| "provinceData":
| [
| {
| "name":"hb",
| "parentName":null,
| "parentId":null,
| "id":"450"
| }
| ]
|}
| """.stripMargin
parse(json).extract[ProvinceJson]
}
When I run this code, it reports compilation error:
could not find implicit value for parameter formats: net.liftweb.json.Formats
parse(json).extract[ProvinceJson]
^
not enough arguments for method extract: (implicit formats: net.liftweb.json.Formats, implicit mf: scala.reflect.Manifest[com.thoughtworks.sfexpress.sf_ws.ProvinceJson])com.thoughtworks.sfexpress.sf_ws.ProvinceJson.
Unspecified value parameters formats, mf.
parse(json).extract[ProvinceJson]
^
Do I miss anything?
You need to tell the parser which formats to use, and to do that the parser looks for an implicit argument. Adding this somewhere in your code should fix things for you:
implicit val formats = net.liftweb.json.DefaultFormats
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With