1
/*
2
* This file is part of the diffson project.
3
* Copyright (c) 2019 Lucas Satabin
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*/
17
package diffson
18

19
import play.api.libs.json._
20

21
package object playJson {
22

23
  implicit object playJsonJsony extends Jsony[JsValue] {
24

25
    val Null: JsValue =
26 1
      play.api.libs.json.JsNull
27

28
    def makeArray(elems: Vector[JsValue]): JsValue =
29 1
      play.api.libs.json.JsArray(elems)
30

31
    def makeObject(fields: Map[String, JsValue]): JsValue =
32 1
      play.api.libs.json.JsObject(fields)
33

34
    def array(value: JsValue): Option[Vector[JsValue]] = value match {
35
      case play.api.libs.json.JsArray(elems) =>
36 1
        Some(elems.toVector)
37
      case _ =>
38 1
        None
39
    }
40

41
    def fields(value: JsValue): Option[Map[String, JsValue]] = value match {
42
      case play.api.libs.json.JsObject(fields) =>
43 1
        Some(fields.toMap)
44
      case _ =>
45 1
        None
46
    }
47

48
    def show(json: JsValue): String =
49 0
      Json.stringify(json)
50

51
    def eqv(json1: JsValue, json2: JsValue): Boolean =
52 1
      json1 == json2
53

54
  }
55
}

Read our documentation on viewing source code .

Loading