Browse files

Fix example

  • Loading branch information...
1 parent ee2a5d1 commit 4a6e82d1f708cbb9b8ad29758d6ba5995aa45099 Joni Freeman committed Mar 11, 2011
Showing with 10 additions and 5 deletions.
  1. +10 −5 core/json-scalaz/README.md
View
15 core/json-scalaz/README.md
@@ -13,14 +13,19 @@ Function 'read' returns an Applicative Functor, enabling parsing in an applicati
Simple example
--------------
- case class Address(street: String, zipCode: String)
- case class Person(name: String, age: Int, address: Address)
+ scala> import scalaz._
+ 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> field[String]("zip")(json) <*> (field[String]("street")(json) map Address.curried)
+ scala> val json = parse(""" {"street": "Manhattan 2", "zip": "00223" } """)
+ scala> (field[String]("street")(json) |@| field[String]("zip")(json)) { Address }
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'")
Notice the required explicit types when reading fields from JSON. The library comes with helpers which

0 comments on commit 4a6e82d

Please sign in to comment.