1
/*
2
* This file is part of the diffson project.
3
* Copyright (c) 2016 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 spray.json.JsValue
20

21
package object sprayJson {
22

23
  implicit object sprayJsonJsony extends Jsony[JsValue] {
24

25
    val Null: JsValue =
26 1
      spray.json.JsNull
27

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

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

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

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

48 0
    def show(t: JsValue) = t.compactPrint
49

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

53
  }
54

55
}

Read our documentation on viewing source code .

Loading