Class

com.rojoma.json.v3.matcher

PObject

Related Doc: package matcher

Permalink

case class PObject(subPatterns: (String, OptPattern)*) extends Pattern with Product with Serializable

A com.rojoma.json.v3.matcher.Pattern which matches if the value is a com.rojoma.json.v3.ast.JObject which contains at least the fields specified in this Pattern. In order to allow fields to not appear at all, the sub-patterns can be wrapped in a com.rojoma.json.v3.matcher.POption.

Example:
  1. val i = Variable[Int]
    val s = Variable[String]
    val b = Variable[Boolean]
    val f = Variable[Float]
    val pattern = PObject(
      "i" -> i,                 // must be present
      "s" -> POption(s),        // may be absent but must not be null
      "b" -> POption(b).orNull, // may be present, absent, or null
      "f" -> FirstOf(f, JNull)  // must be present but may be null
    )
    pattern.matches(jvalue) match {
      case Some(results) =>
        println("i: " + i(results))
        println("s: " + s.getOrElse(results, "[not present]"))
        println("b: " + b.getOrElse(results, "[not present or null]"))
        println("f: " + f.getOrElse(results, "[null]"))
     case None =>
        println("Didn't match")
    }
Linear Supertypes
Serializable, Serializable, Product, Equals, Pattern, OptPattern, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. PObject
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. Pattern
  7. OptPattern
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new PObject(subPatterns: (String, OptPattern)*)

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def evaluate(x: JValue, environment: Results): Either[DecodeError, Results]

    Permalink

    Tests the given com.rojoma.json.v3.ast.JValue against this Pattern, with the restriction that any com.rojoma.json.v3.matcher.Variables that are bound in the environment must match those values if they are re-used in this Pattern.

    Tests the given com.rojoma.json.v3.ast.JValue against this Pattern, with the restriction that any com.rojoma.json.v3.matcher.Variables that are bound in the environment must match those values if they are re-used in this Pattern.

    Generally you won't use this directly, but you can if you want to pre-populate variables.

    x

    The value to test.

    returns

    The environment augmented with any new com.rojoma.json.v3.matcher.Variables encountered in this Pattern, or Left(error) if it didn't match.

    Definition Classes
    PObjectPattern
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. def generate(environment: Results): Option[JObject]

    Permalink

    Uses this Pattern together with the bindings generated as the result of a call to matches or evaluate to produce a com.rojoma.json.v3.ast.JValue.

    Uses this Pattern together with the bindings generated as the result of a call to matches or evaluate to produce a com.rojoma.json.v3.ast.JValue.

    Generally the other generate method is simpler to use.

    returns

    The new com.rojoma.json.v3.ast.JValue, or None if a required com.rojoma.json.v3.matcher.Variable is not bound in the environment, or a matcher which cannot generate is used.

    Definition Classes
    PObjectPattern
  10. def generate(bindings: (Results) ⇒ Results*): JValue

    Permalink

    Uses this Pattern together with the provided variable bindings to generate a new com.rojoma.json.v3.ast.JValue.

    Uses this Pattern together with the provided variable bindings to generate a new com.rojoma.json.v3.ast.JValue.

    returns

    The new com.rojoma.json.v3.ast.JValue

    Definition Classes
    Pattern
    Example:
    1. val intVar = Variable[Int]
      val strVar = Variable[String]
      val pattern = PObject("i" -> intVar, "s" -> POption(strVar))
      pattern.generate(i := 1)                      // { "i" : 1 }
      pattern.generate(i := 1, s := "hello")        // { "i" : 1, "s" : "hello" }
      pattern.generate(i := 1, s :=? None )         // { "i" : 1 }
      pattern.generate(i := 1, s :=? Some("hello")) // { "i" : 1, "s" : "hello" }
    Exceptions thrown

    JsonGenerationException if a required com.rojoma.json.v3.matcher.Variable is not bound or a matcher which cannot generate (such as com.rojoma.json.v3.matcher.AllOf) is used.

  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. def matches(x: JValue): Either[DecodeError, Results]

    Permalink

    Tests the given com.rojoma.json.v3.ast.JValue against this Pattern, and if it matches returns an object that can be used to retrieve the values matched by any com.rojoma.json.v3.matcher.Variables in the Pattern.

    Tests the given com.rojoma.json.v3.ast.JValue against this Pattern, and if it matches returns an object that can be used to retrieve the values matched by any com.rojoma.json.v3.matcher.Variables in the Pattern.

    x

    The value to test.

    returns

    An environment which can be used to look up variable bindings, or Left(error) if it didn't match.

    Definition Classes
    Pattern
    Example:
    1. val intVar = Variable[Int]
      val strVar = Variable[String]
      val pattern = PObject("i" -> intVar, "s" -> strVar)
      pattern.matches(jvalue) match {
        case Right(results) => println("The integer was " + intVar(results))
        case Left(_) => println("It didn't match the pattern")
      }
  14. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. val subPatterns: (String, OptPattern)*

    Permalink
  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  19. def unapply(x: JValue): Option[Results]

    Permalink

    Allows this Pattern to be used in a match expression, with the output being the environment of com.rojoma.json.v3.matcher.Variable bindings as produced by matches.

    Allows this Pattern to be used in a match expression, with the output being the environment of com.rojoma.json.v3.matcher.Variable bindings as produced by matches.

    Definition Classes
    Pattern
    Example:
    1. val intVar = Variable[Int]
      val strVar = Variable[String]
      val Pattern1 = PObject("i" -> intVar, "s" -> strVar)
      val Pattern2 = PObject("hello" -> "world")
      jvalue match {
        case Pattern1(results) => println("The integer was " + intVar(results))
        case Pattern2(result) => println("It was just a hello world object")
        case _ => println("It was something else")
      }
  20. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Pattern

Inherited from OptPattern

Inherited from AnyRef

Inherited from Any

Ungrouped