Package

com.rojoma.json.v3

matcher

Permalink

package matcher

Visibility
  1. Public
  2. All

Type Members

  1. case class AllOf(subPatterns: OptPattern*) extends Pattern with Product with Serializable

    Permalink

    A com.rojoma.json.v3.matcher.Pattern which matches only if all the sub-patterns also match.

    A com.rojoma.json.v3.matcher.Pattern which matches only if all the sub-patterns also match. This pattern cannot be used to generate a com.rojoma.json.v3.ast.JValue.

  2. class DecodeMatcher[T] extends AnyRef

    Permalink

    Simple class to turn a com.rojoma.json.v3.codec.JsonDecode into something that can be used for pattern-matching.

    Simple class to turn a com.rojoma.json.v3.codec.JsonDecode into something that can be used for pattern-matching.

    Example:
    1. val ListOfFoo = DecodeMatcher[List[Foo]]
      val NamedBars = DecodeMatcher[Map[String, Bar]]
      value match {
        case ListOfFoo(foos) => foos.foreach(_.fooify())
        case NamedBars(bars) => bars("hello").doBarring()
        case _ => // didn't match
      }
  3. case class FLiteral(recognizer: (JValue) ⇒ Boolean) extends Pattern with Product with Serializable

    Permalink

    A com.rojoma.json.v3.matcher.Pattern which matches a com.rojoma.json.v3.ast.JValue if a predicate on that JValue is true.

    A com.rojoma.json.v3.matcher.Pattern which matches a com.rojoma.json.v3.ast.JValue if a predicate on that JValue is true. This Pattern cannot be used to generate a com.rojoma.json.v3.ast.JValue.

  4. case class FirstOf(subPatterns: Pattern*) extends Pattern with Product with Serializable

    Permalink

    A com.rojoma.json.v3.matcher.Pattern which matches the first sub-pattern to succeed.

    A com.rojoma.json.v3.matcher.Pattern which matches the first sub-pattern to succeed. This is frequently used to allow a value to be something-or-null.

  5. class JsonGenerationException extends RuntimeException

    Permalink
  6. case class Literal(literal: JValue) extends Pattern with Product with Serializable

    Permalink

    A com.rojoma.json.v3.matcher.Pattern which matches a com.rojoma.json.v3.ast.JValue exactly.

    A com.rojoma.json.v3.matcher.Pattern which matches a com.rojoma.json.v3.ast.JValue exactly. Generally this is not used explicitly; com.rojoma.json.v3.ast.JValues can be implicitly converted into Literals.

  7. sealed trait OptPattern extends AnyRef

    Permalink

    Either a com.rojoma.json.v3.matcher.Pattern or a com.rojoma.json.v3.matcher.POption.

  8. case class PArray(subPatterns: Pattern*) extends Pattern with Product with Serializable

    Permalink

    A com.rojoma.json.v3.matcher.Pattern which matches if the value is a com.rojoma.json.v3.ast.JArray which contains at least as many elements as sub-patterns contained by this object and those elements match the sub-patterns in the order given.

    A com.rojoma.json.v3.matcher.Pattern which matches if the value is a com.rojoma.json.v3.ast.JArray which contains at least as many elements as sub-patterns contained by this object and those elements match the sub-patterns in the order given.

    For the more common case where a sequence of repeated objects of a particular type is desired, use a com.rojoma.json.v3.matcher.Variable of some Seq[T].

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

    Permalink

    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.

    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")
      }
  10. case class POption(subPattern: Pattern) extends OptPattern with Product with Serializable

    Permalink

    A wrapper for a com.rojoma.json.v3.matcher.Pattern which allows fields to be absent when using a com.rojoma.json.v3.matcher.PObject.

    A wrapper for a com.rojoma.json.v3.matcher.Pattern which allows fields to be absent when using a com.rojoma.json.v3.matcher.PObject.

    See also

    com.rojoma.json.v3.matcher.PObject

  11. trait Pattern extends OptPattern

    Permalink

    An object that can be used to either match and extract data from, or generate, com.rojoma.json.v3.ast.JValues.

  12. abstract class Variable[T] extends Pattern with PartialFunction[Results, T]

    Permalink

    A com.rojoma.json.v3.matcher.Pattern which matches any com.rojoma.json.v3.ast.JValue which can be decoded into an object of type T.

    A com.rojoma.json.v3.matcher.Pattern which matches any com.rojoma.json.v3.ast.JValue which can be decoded into an object of type T. If this variable is already bound in the environment at match-time, then this matches only if the two decoded objects are equal, in which case the environment is unchanged.

Value Members

  1. object DecodeMatcher

    Permalink
  2. object OptPattern extends LowPriorityImplicits

    Permalink
  3. object Pattern

    Permalink
  4. object Variable

    Permalink

Ungrouped