ReaderSyntax

final class ReaderSyntax(jv: JValue) extends AnyVal
class AnyVal
trait Matchable
class Any

Value members

Concrete methods

def as[A](implicit reader: Reader[A]): A

Given that an implicit reader of type A is in scope It will deserialize the org.json4s.JValue to an object of type A

Given that an implicit reader of type A is in scope It will deserialize the org.json4s.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]
Source:
ReaderSyntax.scala
def getAs[A](implicit reader: Reader[A]): Option[A]

Given that an implicit reader of type A is in scope It will deserialize the org.json4s.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.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]
Source:
ReaderSyntax.scala
def getAsOrElse[A](default: => A)(implicit reader: Reader[A]): A

Given that an implicit reader of type A is in scope It will deserialize the org.json4s.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.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"))
Source:
ReaderSyntax.scala