Play JSON
Builds Play JSON Reads and Writes out of JSON schema definitions.
"org.julienrf" %% "endpoints-json-schema-playjson" % "0.15.0"
The JsonSchemas
interpreter fixes the JsonSchema[A]
type to a type that provides both a Reads[A]
and a Writes[A]
.
Given the following type definition:
sealed trait Shape
case class Circle(radius: Double) extends Shape
case class Rectangle(width: Double, height: Double) extends Shape
Assuming that there is an implicit JsonSchema[Shape]
definition, we can encode a Shape
into JSON and decode it using the usual Play JSON operations:
import JsonSchema._
val shape: Shape = Circle(42)
val shapeJson: JsValue = Json.toJson(shape)
val maybeShape: JsResult[Shape] = Json.fromJson[Shape](shapeJson)
0.15.0