Scala PlayJson is no longer supported by this library. The following Scala code is provided as an unmaintained example of how to implement this yourself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54import com.atlassian.adf.jackson2.AdfJackson2 import com.atlassian.adf.model.node.Doc import com.atlassian.adf.parser.{AdfParser, JsonParser} import com.fasterxml.jackson.databind.JsonNode import play.api.libs.json.{EnvReads, EnvWrites, Format, JsResult, JsValue, Json, Reads, Writes} import scala.util.Try /** * An ADF marshaller/unmarshaller that delegates to Play JSON for its JSON encoding and parsing. */ class AdfPlayJson extends AdfParser[String] { /** * The same underlying parser, but using concrete [[JsValue]] objects as the transport format * instead of JSON strings. */ def useJsValue(): AdfParser[JsValue] = AdfPlayJson.useJsValue override def unmarshall(value: String): Doc = AdfPlayJson.useJsValue.unmarshall(Json.parse(value)) override def marshall(doc: Doc): String = Json.stringify(AdfPlayJson.useJsValue.marshall(doc)) override def jsonParser(): JsonParser = AdfPlayJson.jsonParser } object AdfPlayJson extends EnvWrites with EnvReads { private lazy val adfParser: AdfJackson2 = new AdfJackson2() private lazy val adfParserJsonNode: AdfParser[JsonNode] = adfParser.useJsonNode() private lazy val jsonParser: JsonParser = AdfPlayJson.adfParser.jsonParser() private lazy val useJsValue: AdfParser[JsValue] = new UseJsValue() object Implicits { implicit val reads: Reads[Doc] = JsonNodeReads.flatMapResult { node => JsResult.fromTry(Try(adfParserJsonNode.unmarshall(node))) } implicit val writes: Writes[Doc] = jsonNodeWrites.contramap(adfParserJsonNode.marshall) implicit val format: Format[Doc] = Format(reads, writes) } private class UseJsValue extends AdfParser[JsValue] { import AdfPlayJson.Implicits._ override def jsonParser(): JsonParser = AdfPlayJson.jsonParser override def unmarshall(value: JsValue): Doc = value.as[Doc] override def marshall(doc: Doc): JsValue = Json.toJson(doc) } }
Note that these require a test dependency on the adf-builder-java-tck module:
1 2 3 4 5import com.atlassian.adf.tck.AdfTckTest class AdfPlayJson2StringTest extends AdfTckTest[String](new AdfPlayJson()) { }
1 2 3 4 5 6import com.atlassian.adf.tck.AdfTckTest import play.api.libs.json.JsValue class AdfPlayJson2JsValueTest extends AdfTckTest[JsValue](new AdfPlayJson().useJsValue()) { }
Rate this page: