Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix example

  • Loading branch information...
commit 4a6e82d1f708cbb9b8ad29758d6ba5995aa45099 1 parent ee2a5d1
Joni Freeman authored
Showing with 10 additions and 5 deletions.
  1. +10 −5 core/json-scalaz/README.md
15 core/json-scalaz/README.md
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.