Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 47 lines (40 sloc) 1.125 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
package net.liftweb
package json

import org.specs.Specification
import org.specs.runner.{Runner, JUnit}

class PullParserExampleTest extends Runner(PullParserExample) with JUnit
object PullParserExample extends Specification {
  import JsonParser._

  "Pull parsing example" in {
    val parser = (p: Parser) => {
      def parse: BigInt = p.nextToken match {
        case FieldStart("postalCode") => p.nextToken match {
          case IntVal(code) => code
          case _ => p.fail("expected int")
        }
        case End => p.fail("no field named 'postalCode'")
        case _ => parse
      }

      parse
    }

    val postalCode = parse(json, parser)
    postalCode mustEqual 10021
  }

  val json = """
{
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
{ "type": "home", "number": "212 555-1234" },
{ "type": "fax", "number": "646 555-4567" }
],
"newSubscription": false,
"companyName": null
}"""
}
Something went wrong with that request. Please try again.