Skip to content

Commit

Permalink
Fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
Joni Freeman committed Mar 11, 2011
1 parent ee2a5d1 commit 4a6e82d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core/json-scalaz/README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ Function 'read' returns an Applicative Functor, enabling parsing in an applicati
Simple example Simple example
-------------- --------------


case class Address(street: String, zipCode: String) scala> import scalaz._
case class Person(name: String, age: Int, address: Address) scala> import Scalaz._
scala> import net.liftweb.json.scalaz.JsonScalaz._
scala> import net.liftweb.json._

scala> case class Address(street: String, zipCode: String)
scala> case class Person(name: String, age: Int, address: Address)


scala> val json = JsonParser.parse(""" {"street": "Manhattan 2", "zip": "00223" } """) scala> val json = parse(""" {"street": "Manhattan 2", "zip": "00223" } """)
scala> field[String]("zip")(json) <*> (field[String]("street")(json) map Address.curried) scala> (field[String]("street")(json) |@| field[String]("zip")(json)) { Address }
res0: Success(Address(Manhattan 2,00223)) res0: Success(Address(Manhattan 2,00223))


scala> field[String]("zip")(json) <*> (field[String]("streets")(json) map Address.curried) scala> (field[String]("streets")(json) |@| field[String]("zip")(json)) { Address }
res1: Failure("no such field 'streets'") res1: Failure("no such field 'streets'")


Notice the required explicit types when reading fields from JSON. The library comes with helpers which Notice the required explicit types when reading fields from JSON. The library comes with helpers which
Expand Down

0 comments on commit 4a6e82d

Please sign in to comment.