pjan / play-json-scalactic

Scalactic support for Play's JSON library

GitHub

Play JSON Scalactic Library

An unofficial library that provides Play JSON (un)marshallers for Scalactic types

Features

  • Supports most types, including Or, Good, Bad, Every, One, Many .
  • Type safe and polymorphic serialisation and deserialisation for Every, polymorphic serialisation of Or.

Installation instructions

Add the following dependency to build.sbt:

resolvers += "pjan at bintray" at "http://dl.bintray.com/pjan/maven"

"io.pjan" %% "play-json-scalactic" % "0.1.0"

Usage instructions

Import the implicit Reads and/or Writes, or mix them in. There's traits and objects separately for Reads and Writes (ScalacticReads and ScalacticWrites respectively), and ScalacticFormats combining both.

import play.extras.json.scalactic.ScalacticFormats._

Serialise a Scalactic type/object to a JSON:

val errors: Every[String] = Every("first error", "second error")
val json = Json.toJson(errors)

Deserialise some JSON into a Scalactic object:

val oneJson = Json.arr("lone element")
val manyJson = Json.arr("first element", "second element")

val one = Json.fromJson[Every[String]](oneJson)
val many = Json.fromJson[Every[String]](manyJson)

val goodJson = JsString("good")
val good = Json.fromJson[Good[String]](goodJson)