Skip to content

Commit edd2ac2

Browse files
committed
merging from master
2 parents f6464a0 + 82b422f commit edd2ac2

7 files changed

Lines changed: 27 additions & 56 deletions

File tree

README.markdown

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ as depicted in this diagram:
2020
### Installation
2121

2222
_spray-json_ is available from maven central.
23-
24-
Latest release: [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.spray/spray-json_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.spray/spray-json_2.12)
23+
The latest release is `1.3.3` and is built against Scala 2.10.x, 2.11.x, and 2.12.x.
2524

2625
If you use SBT you can include _spray-json_ in your project with
2726

@@ -42,25 +41,26 @@ import DefaultJsonProtocol._ // if you don't supply your own Protocol (see below
4241
and do one or more of the following:
4342

4443
* Parse a JSON string into its Abstract Syntax Tree (AST) representation
45-
44+
4645
```scala
4746
val source = """{ "some": "JSON source" }"""
4847
val jsonAst = source.parseJson // or JsonParser(source)
4948
```
50-
49+
5150
* Print a JSON AST back to a String using either the `CompactPrinter` or the `PrettyPrinter`
52-
51+
5352
```scala
5453
val json = jsonAst.prettyPrint // or .compactPrint
5554
```
5655

57-
* Convert any Scala object to a JSON AST using the `toJson` extension method
56+
* Convert any Scala object to a JSON AST using the pimped `toJson` method
57+
5858
```scala
5959
val jsonAst = List(1, 2, 3).toJson
6060
```
61-
61+
6262
* Convert a JSON AST to a Scala object with the `convertTo` method
63-
63+
6464
```scala
6565
val myObject = jsonAst.convertTo[MyObjectType]
6666
```
@@ -243,38 +243,6 @@ object MyJsonProtocol extends DefaultJsonProtocol {
243243
This is a bit more verbose in its definition and the resulting JSON but transports the field semantics over to the
244244
JSON side. Note that this is the approach _spray-json_ uses for case classes.
245245

246-
### Providing JsonFormats for unboxed types
247-
248-
A value class
249-
250-
```scala
251-
case class PhoneNumber(value: String) extends AnyVal
252-
val num = PhoneNumber("+1 212 555 1111")
253-
```
254-
255-
or a class with multiple members
256-
257-
```scala
258-
case class Money(currency: String, amount: BigDecimal)
259-
val bal = Money("USD", 100)
260-
```
261-
262-
can be handled as above with `jsonFormatX`, etc.
263-
It may be preferable, however, to serialize such instances without object boxing:
264-
as `"USD 100"` instead of `{"currency":"USD","amount":100}`.
265-
This requires explicit (de)serialization logic:
266-
267-
```scala
268-
implicit object MoneyFormat extends JsonFormat[Money] {
269-
val fmt = """([A-Z]{3}) ([0-9.]+)""".r
270-
def write(m: Money) = JsString(s"${m.currency} ${m.amount}")
271-
def read(json: JsValue) = json match {
272-
case JsString(fmt(c, a)) => Money(c, BigDecimal(a))
273-
case _ => deserializationError("String expected")
274-
}
275-
}
276-
```
277-
278246

279247
### JsonFormat vs. RootJsonFormat
280248

@@ -329,22 +297,20 @@ _spray-json_ is licensed under [APL 2.0].
329297

330298
### Mailing list
331299

332-
Spray-json is in primarily "maintanance mode", as it contains the basic functionality it is meant to deliver.
333-
If you have any questions about it though, please open issues on this repository.
334-
300+
Please use the [spray-user] mailing list if you have any questions.
335301

336-
### Maintanance mode
337302

338-
_spray-json_ is largely considered feature-complete for the basic functionality it provides.
339-
It is currently maintained by the Akka team at Lightbend.
303+
### Patch Policy
340304

341305
Feedback and contributions to the project, no matter what kind, are always very welcome.
342-
306+
However, patches can only be accepted from their original author.
343307
Along with any patches, please state that the patch is your original work and that you license the work to the
344308
_spray-json_ project under the project’s open source license.
345309

346310

347311
[JSON]: http://json.org
312+
[repo.spray.io]: http://repo.spray.io
348313
[SJSON]: https://github.com/debasishg/sjson
349-
[Databinder-Dispatch]: https://github.com/dispatch/classic
314+
[Databinder-Dispatch]: https://github.com/n8han/Databinder-Dispatch
350315
[APL 2.0]: http://www.apache.org/licenses/LICENSE-2.0
316+
[spray-user]: http://groups.google.com/group/spray-user

src/main/scala/spray/json/JsValue.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright (C) 2009-2011 Mathias Doenitz
33
* Inspired by a similar implementation by Nathan Hamblen
4-
* (https://github.com/dispatch/classic)
4+
* (https://github.com/n8han/Databinder-Dispatch)
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@ sealed abstract class JsValue {
2828
def toString(printer: (JsValue => String)) = printer(this)
2929
def compactPrint = CompactPrinter(this)
3030
def prettyPrint = PrettyPrinter(this)
31-
def sortedPrint = SortedPrinter(this)
3231
def convertTo[T :JsonReader]: T = jsonReader[T].read(this)
3332

3433
/**
@@ -124,5 +123,5 @@ case object JsFalse extends JsBoolean {
124123
*/
125124
case object JsNull extends JsValue
126125

127-
/** The representation for JSON missing value. **/
126+
/** The representation for JSON undefined. **/
128127
case object JsUndefined extends JsValue

src/main/scala/spray/json/JsonParser.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class JsonParser(input: ParserInput) {
6060
(cursorChar: @switch) match {
6161
case 'f' => simpleValue(`false`(), JsFalse)
6262
case 'n' => simpleValue(`null`(), JsNull)
63+
case 'u' => simpleValue(`undefined`(), JsUndefined)
6364
case 't' => simpleValue(`true`(), JsTrue)
6465
case '{' => advance(); `object`()
6566
case '[' => advance(); `array`()
@@ -71,6 +72,7 @@ class JsonParser(input: ParserInput) {
7172

7273
private def `false`() = advance() && ch('a') && ch('l') && ch('s') && ws('e')
7374
private def `null`() = advance() && ch('u') && ch('l') && ws('l')
75+
private def `undefined`() = advance() && ch('n') && ch('d') && ch('e') && ch('f') && ch('i') && ch('n') && ch('e') && ws('d')
7476
private def `true`() = advance() && ch('r') && ch('u') && ws('e')
7577

7678
// http://tools.ietf.org/html/rfc4627#section-2.2

src/main/scala/spray/json/JsonPrinter.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ trait JsonPrinter extends (JsValue => String) {
4444
protected def printLeaf(x: JsValue, sb: JStringBuilder) {
4545
x match {
4646
case JsNull => sb.append("null")
47+
case JsUndefined => sb.append("undefined")
4748
case JsTrue => sb.append("true")
4849
case JsFalse => sb.append("false")
4950
case JsNumber(x) => sb.append(x)

src/test/scala/spray/json/CompactPrinterSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class CompactPrinterSpec extends Specification {
8181
mustEqual "{}"
8282
)
8383
"properly print a simple JsArray" in (
84-
CompactPrinter(JsArray(JsNull, JsNumber(1.23), JsObject("key" -> JsBoolean(true))))
85-
mustEqual """[null,1.23,{"key":true}]"""
84+
CompactPrinter(JsArray(JsNull, JsUndefined, JsNumber(1.23), JsObject("key" -> JsBoolean(true))))
85+
mustEqual """[null,undefined,1.23,{"key":true}]"""
8686
)
8787
"properly print a JSON padding (JSONP) if requested" in {
8888
CompactPrinter(JsTrue, Some("customCallback")) mustEqual("customCallback(true)")

src/test/scala/spray/json/JsonParserSpec.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class JsonParserSpec extends Specification {
2424
"parse 'null' to JsNull" in {
2525
JsonParser("null") === JsNull
2626
}
27+
"parse 'undefined' to JsUndefined" in {
28+
JsonParser("undefined") === JsUndefined
29+
}
2730
"parse 'true' to JsTrue" in {
2831
JsonParser("true") === JsTrue
2932
}
@@ -57,8 +60,8 @@ class JsonParserSpec extends Specification {
5760
JsObject("key" -> JsNumber(42), "key2" -> JsString("value"))
5861
)
5962
"parse a simple JsArray" in (
60-
JsonParser("""[null, 1.23 ,{"key":true } ] """) ===
61-
JsArray(JsNull, JsNumber(1.23), JsObject("key" -> JsTrue))
63+
JsonParser("""[null, undefined, 1.23 ,{"key":true } ] """) ===
64+
JsArray(JsNull, JsUndefined, JsNumber(1.23), JsObject("key" -> JsTrue))
6265
)
6366
"parse directly from UTF-8 encoded bytes" in {
6467
val json = JsObject(

src/test/scala/spray/json/ProductFormatsSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ProductFormatsSpec extends Specification {
6060
JsObject("b" -> JsNumber(4.2)).convertTo[Test2] must
6161
throwA(new DeserializationException("Object is missing required member 'a'"))
6262
)
63-
"not require the presence of Option fields for deserialization" in {
63+
"not require the presence of optional fields for deserialization" in {
6464
JsObject("a" -> JsNumber(42)).convertTo[Test2] mustEqual Test2(42, None)
6565
}
6666
"not require the presence of Tription fields for deserialization" in {

0 commit comments

Comments
 (0)