Given that an implicit reader of type A
is in scope
It will deserialize the org.json4s.JsonAST.JValue to an object of type A
Given that an implicit reader of type A
is in scope
It will deserialize the org.json4s.JsonAST.JValue to an object of type A
Example:
case class Person(name: String) implicit object PersonReader extends Reader[Person] { def read(json: JValue): Person = Person((json \ "name").extract[String]) } JObject(JField("name", JString("Joe")) :: Nil).as[Person]
Extract a value from a JSON.
Extract a value from a JSON.
Value can be:
Example:
case class Person(name: String) JObject(JField("name", JString("joe")) :: Nil).extract[Person] == Person("joe")
Extract a value from a JSON.
Extract a value from a JSON.
Value can be:
Example:
case class Person(name: String) JObject(JField("name", JString("joe")) :: Nil).extractOpt[Person] == Some(Person("joe"))
Extract a value from a JSON using a default value.
Extract a value from a JSON using a default value.
Value can be:
Example:
case class Person(name: String) JNothing.extractOrElse(Person("joe")) == Person("joe")
Given that an implicit reader of type A
is in scope
It will deserialize the org.json4s.JsonAST.JValue to an object of type Option[A
]
Given that an implicit reader of type A
is in scope
It will deserialize the org.json4s.JsonAST.JValue to an object of type Option[A
]
Example:
case class Person(name: String) implicit object PersonReader extends Reader[Person] { def read(json: JValue): Person = Person((json \ "name").extract[String]) } JObject(JField("name", JString("Joe")) :: Nil).getAs[Person]
Given that an implicit reader of type A
is in scope
It will deserialize the org.json4s.JsonAST.JValue to an object of type A
if an error occurs it will return the default value.
Given that an implicit reader of type A
is in scope
It will deserialize the org.json4s.JsonAST.JValue to an object of type A
if an error occurs it will return the default value.
Example:
case class Person(name: String) implicit object PersonReader extends Reader[Person] { def read(json: JValue): Person = Person((json \ "name").extract[String]) } JObject(JField("name", JString("Joe")) :: Nil).getAsOrElse(Person("Tom"))