Package

com.wellfactored

playbindings

Permalink

package playbindings

Visibility
  1. Public
  2. All

Type Members

  1. trait PlayBindings[V, W] extends AnyRef

    Permalink
  2. trait PlayValueWrapper[V, W] extends AnyRef

    Permalink

    This trait defines implicits for the common Play Framework transformations on values.

    This trait defines implicits for the common Play Framework transformations on values. Namely: - A Reads[W] to read from json - A Writes[W] to write to json - A PathBindable to convert to and from strings in the url pattern - A QueryStringBindable to convert to and from url query parameters

    To use this with, for instance, a case class that extends AnyVal, create a companion object that extends this trait with V being the primitive type (e.g. String, Int) and W being the wrapped type. Then make an implicit instance of ValueWrapper[V,W] within the companion object, defining the appropriate wrap and unwrap methods.

  3. trait SimpleWrapper[V, W] extends ValidatingWrapper[V, W]

    Permalink
  4. trait ValidatingWrapper[V, W] extends PlayValueWrapper[V, W]

    Permalink
  5. trait ValueWrapper[V, W] extends AnyRef

    Permalink

    Defines an interface that can take a value of type V and wrap it in an instance of type W, and take a W and unwrap it to a V.

    Defines an interface that can take a value of type V and wrap it in an instance of type W, and take a W and unwrap it to a V.

    For example, if W is case class Foo(value:String) extends AnyVal then we can create an instance of ValueWrapper as:

    implicit val FooValueWrapper extends ValueWrapper[String, Foo] {
      def wrap(v:String) : Either[String, Foo] = Right(Foo(v))
      def unwrap(f:Foo) = foo.value
    }

    The wrap method returns Either[String, W] to allow for situations where the V being passed in cannot be converted to a W.

    By making this a type class we can re-use instances of it in a number of places, for example to remove a great deal of boilerplace when creating instances of Play Framework json formatters and url path binders for case classes that extend AnyVal

    V

    the type of the value that is being wrapped

    W

    the type of the wrapper instance

Value Members

  1. object PlayBindings

    Permalink
  2. object PlayValueWrapper

    Permalink

    Provide functions to create various Play type class instances for types that implement a ValueWrapper

Ungrouped