summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown4
-rw-r--r--src/main/scala/cc/spray/json/package.scala8
-rw-r--r--src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala2
-rw-r--r--src/test/scala/cc/spray/json/CustomFormatSpec.scala2
-rw-r--r--src/test/scala/cc/spray/json/ReadmeSpec.scala4
5 files changed, 12 insertions, 8 deletions
diff --git a/README.markdown b/README.markdown
index fb35301..3ff1d02 100644
--- a/README.markdown
+++ b/README.markdown
@@ -32,8 +32,8 @@ and do one or more of the following:
1. Parse a JSON string into its Abstract Syntax Tree (AST) representation
- val json = """{ "some": "JSON source" }"""
- val jsonAst = JsonParser(json)
+ val source = """{ "some": "JSON source" }"""
+ val jsonAst = source.asJson // or JsonParser(source)
2. Print a JSON AST back to a String using either the `CompactPrinter` or the `PrettyPrinter`
diff --git a/src/main/scala/cc/spray/json/package.scala b/src/main/scala/cc/spray/json/package.scala
index 1bc592f..ec12939 100644
--- a/src/main/scala/cc/spray/json/package.scala
+++ b/src/main/scala/cc/spray/json/package.scala
@@ -26,8 +26,8 @@ package object json {
def jsonReader[T](implicit reader: JsonReader[T]) = reader
def jsonWriter[T](implicit writer: JsonWriter[T]) = writer
- implicit def pimpAny[T](any: T): PimpedAny[T] = new PimpedAny(any)
-
+ implicit def pimpAny[T](any: T) = new PimpedAny(any)
+ implicit def pimpString(string: String) = new PimpedString(string)
}
package json {
@@ -38,4 +38,8 @@ package json {
private[json] class PimpedAny[T](any: T) {
def toJson(implicit writer: JsonWriter[T]): JsValue = writer.write(any)
}
+
+ private[json] class PimpedString(string: String) {
+ def asJson: JsValue = JsonParser(string)
+ }
} \ No newline at end of file
diff --git a/src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala b/src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala
index 217ae4a..f25c9d8 100644
--- a/src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala
+++ b/src/test/scala/cc/spray/json/AdditionalFormatsSpec.scala
@@ -51,7 +51,7 @@ class AdditionalFormatsSpec extends Specification {
"properly read a Container[Container[List[Int]]] from JSON" in {
import ReaderProtocol._
- JsonParser("""{"content":{"content":[1,2,3]}}""").convertTo[Container[Container[List[Int]]]] mustEqual obj
+ """{"content":{"content":[1,2,3]}}""".asJson.convertTo[Container[Container[List[Int]]]] mustEqual obj
}
}
diff --git a/src/test/scala/cc/spray/json/CustomFormatSpec.scala b/src/test/scala/cc/spray/json/CustomFormatSpec.scala
index 237e3f4..e8feb59 100644
--- a/src/test/scala/cc/spray/json/CustomFormatSpec.scala
+++ b/src/test/scala/cc/spray/json/CustomFormatSpec.scala
@@ -35,7 +35,7 @@ class CustomFormatSpec extends Specification with DefaultJsonProtocol {
"A custom JsonFormat built with 'asJsonObject'" should {
val value = MyType("bob", 42)
"correctly deserialize valid JSON content" in {
- JsonParser("""{ "name": "bob", "value": 42 }""").convertTo[MyType] mustEqual value
+ """{ "name": "bob", "value": 42 }""".asJson.convertTo[MyType] mustEqual value
}
"support full round-trip (de)serialization" in {
value.toJson.convertTo[MyType] mustEqual value
diff --git a/src/test/scala/cc/spray/json/ReadmeSpec.scala b/src/test/scala/cc/spray/json/ReadmeSpec.scala
index 7e1d246..d60aa69 100644
--- a/src/test/scala/cc/spray/json/ReadmeSpec.scala
+++ b/src/test/scala/cc/spray/json/ReadmeSpec.scala
@@ -24,8 +24,8 @@ class ReadmeSpec extends Specification {
"behave as expected" in {
import DefaultJsonProtocol._
- val json = """{ "some": "JSON source" }"""
- val jsonAst = JsonParser(json)
+ val source = """{ "some": "JSON source" }"""
+ val jsonAst = source.asJson
jsonAst mustEqual JsObject("some" -> JsString("JSON source"))
val json2 = PrettyPrinter(jsonAst)