Package

com.rayrobdod.json

builder

Permalink

package builder

Contains the various built-in builders.

Most built-in builders either build a serialized form (json, cbor), build a generic collection class (seq, map) or build a class that conforms to a stereotype (java bean, case class)

Source
package.scala
Linear Supertypes
Content Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. builder
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait Builder[-Key, -Value, +Failure, +Result] extends AnyRef

    Permalink

    An object which takes a series of key-value pairs and combines them into an object using a series of fold-left style method calls.

    An object which takes a series of key-value pairs and combines them into an object using a series of fold-left style method calls.

    Key

    the type of keys used by the Parser that this Builder will be used by

    Value

    the type of primitive value types used by the Parser that this Builder will be used by

    Failure

    possible ways this builder can fail

    Result

    the type of object built by this Builder

    Version

    4.0

    See also

    com.rayrobdod.json.parser.Parser

  2. final class CborBuilder extends Builder[CborValue, CborValue, Nothing, Seq[Byte]]

    Permalink

    A builder whose output is a cbor-formatted byte string.

    A builder whose output is a cbor-formatted byte string.

    Regarding numbers

    • this knows how to write big ints (tag 2 or 3), big decimals (tag 4) and rationals (tag 30)
    • this does not know how to write half-floats
    • it will write the number using the first that can represent the value losslessly: Integer, Big Int, Float, Double, Big Decimal, Rational

    I imagine giving this thing enough key-value pairs will result in an OutOfMemoryError when it tries to create the byte array, but I have yet to go about trying to detect and fast-fail in that situation, or creating a structure that is indistinguishable from a really long byte array

    And beyond that, Cbor maps and arrays have a hard size limit of 2 ** 64 - 1 entries, even if the byte array size issue is overcome. Well, assuming they're fixed arrays and not indefinite arrays, but so far this only writes definite-length arrays.

    Version

    4.0

    Since

    3.0

    See also

    http://tools.ietf.org/html/rfc7049

  3. final class MapBuilder[K, V, F, Inner] extends Builder[K, V, F, Map[K, Either[Inner, V]]]

    Permalink

    A builder that creates maps.

    A builder that creates maps.

    Version

    4.0

  4. final class PiecewiseBuilder[Key, Value, Subject] extends Builder[Key, Value, Failures, Subject]

    Permalink

    A Builder which can be built piecewise.

    A Builder which can be built piecewise.

    Key

    the key types

    Value

    the primitive value types

    Subject

    the type of object to build

    Example:
    1. case class Foo(a:String, b:Seq[JsonValue], c:String)
      val fooBuilder = (new PiecewiseBuilder[StringOrInt, JsonValue, Foo](new Foo("", Seq.empty, ""))
      	.addDef(StringOrInt("a"), partitionedPrimitiveKeyDef({case JsonValueString(x) => Right(x)}, {(f:Foo, x:String) => f.copy(a = x)}))
      	.addDef(StringOrInt("c"), partitionedPrimitiveKeyDef({case JsonValueString(x) => Right(x)}, {(f:Foo, x:String) => f.copy(c = x)}))
      	.addDef(StringOrInt("b"), partitionedComplexKeyDef(new PrimitiveSeqBuilder[JsonValue], {(f:Foo, x:Seq[JsonValue]) => Right(f.copy(b = x))}))
      )
      val jsonParser = new JsonParser
      jsonParser.parse(fooBuilder, """{"a":"","b":[]}""")
      // results in `Foo("", Seq.empty, "")`
      jsonParser.parse(fooBuilder, """{"a":"qwer","b":["z","x","c"],"c":"asdf"}""")
      // results in `Foo("qwer", Seq(JsonValueString("z"), JsonValueString("x"),JsonValueString("c")), "asdf")`
    Version

    4.0

    Since

    3.0

    See also

    Inspired by https://github.com/scopt/scopt/

  5. final class PrettyJsonBuilder extends Builder[StringOrInt, JsonValue, Failures, String]

    Permalink

    A builder whose output is a json-formatted string.

    A builder whose output is a json-formatted string.

    I imagine giving this thing enough key-value pairs will result in an OutOfMemoryError when it tries to create the string, but I have yet to go about trying to detect and fast-fail in that situation, or creating a structure that is indistinguishable from a really long Seq[Char]

    Version

    4.0

    Since

    3.0

    See also

    http://json.org/

  6. final class PrimitiveSeqBuilder[Value, Failure] extends Builder[Any, Value, Failure, Seq[Value]]

    Permalink

    A Builder that will build a Vector of values, where each inner value is a primitive value.

    A Builder that will build a Vector of values, where each inner value is a primitive value.

    This builder ignores keys completely, and adds elements to the sequence in encounter order.

    #apply will return a left if the value is a complex value.

    Value

    the type of primitive values encountered

    Failure

    the type of failure to return if this encounters a complex value

    Version

    4.0

    Since

    3.0

  7. final class SeqBuilder[-Key, -Value, +Failure, Inner] extends Builder[Key, Value, Failure, Seq[Inner]]

    Permalink

    A Builder that will build a Vector of values, where each inner value is produced by the parameter builder.

    A Builder that will build a Vector of values, where each inner value is produced by the parameter builder.

    This builder ignores keys completely, and adds elements to the sequence in encounter order.

    #apply will return a left if the value is a primitive value.

    Key

    the type of keys encountered

    Value

    the type of primitive values encountered

    Inner

    the type of complex values produced by the childBuilder

    Version

    4.0

  8. final class ThrowBuilder[Failure] extends Builder[Any, Any, Failure, Nothing]

    Permalink

    A Builder that will always return a failure on call to apply or finish

    A Builder that will always return a failure on call to apply or finish

    Mostly useful when a function wants a builder even though you 'know' the result must be primitive

    Since

    4.0

Value Members

  1. object CborBuilder

    Permalink
  2. object MapBuilder

    Permalink

    Holds MapChildBuilder and several MapBuilder factory methods

    Holds MapChildBuilder and several MapBuilder factory methods

    Since

    3.0

  3. object PiecewiseBuilder

    Permalink

    KeyDef and several implementations

    KeyDef and several implementations

    Version

    4.0

    Since

    3.0

  4. object PrettyJsonBuilder

    Permalink

    PrettyParams and two implementations of it.

    PrettyParams and two implementations of it.

    Since

    3.0

  5. object PrimitiveSeqBuilder

    Permalink

    Since

    4.0

  6. object SeqBuilder

    Permalink

    Since

    4.0

Inherited from AnyRef

Inherited from Any

Ungrouped