Skip to content

Commit

Permalink
Add support for Scala 2.13.0-M4 (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k authored and jrudolph committed Aug 7, 2018
1 parent 3e4d7da commit 0131537
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ scala:
- 2.10.7
- 2.11.12
- 2.12.6
- 2.13.0-M4

script:
- sbt "++ ${TRAVIS_SCALA_VERSION}!" test mimaReportBinaryIssues
jdk:
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mimaBinaryIssueFilters := Seq(
// publishing
///////////////

crossScalaVersions := Seq("2.12.6", "2.10.7", "2.11.12")
crossScalaVersions := Seq("2.12.6", "2.10.7", "2.11.12", "2.13.0-M4")

publishMavenStyle := true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait ProductFormatsInstances { self: ProductFormats with StandardFormats =>
fields.sizeHint(1 * 2)
[#fields ++= productElement##2Field[P1](fieldName1, p, 0)#
]
JsObject(fields: _*)
JsObject(fields.toSeq: _*)
}
def read(value: JsValue) = {
[#val p1V = fromField[P1](value, fieldName1)#
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/spray/json/CollectionFormats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait CollectionFormats {
implicit def listFormat[T :JsonFormat] = new RootJsonFormat[List[T]] {
def write(list: List[T]) = JsArray(list.map(_.toJson).toVector)
def read(value: JsValue): List[T] = value match {
case JsArray(elements) => elements.map(_.convertTo[T])(collection.breakOut)
case JsArray(elements) => elements.toIterator.map(_.convertTo[T]).toList
case x => deserializationError("Expected List as JsArray, but got " + x)
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ trait CollectionFormats {
def read(value: JsValue) = value match {
case x: JsObject => x.fields.map { field =>
(JsString(field._1).convertTo[K], field._2.convertTo[V])
} (collection.breakOut)
}
case x => deserializationError("Expected Map as JsObject, but got " + x)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/spray/json/JsValue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ sealed abstract class JsValue {
*/
case class JsObject(fields: Map[String, JsValue]) extends JsValue {
override def asJsObject(errorMsg: String) = this
def getFields(fieldNames: String*): immutable.Seq[JsValue] = fieldNames.flatMap(fields.get)(collection.breakOut)
def getFields(fieldNames: String*): immutable.Seq[JsValue] = fieldNames.toIterator.flatMap(fields.get).toList
}
object JsObject {
val empty = JsObject(Map.empty[String, JsValue])
Expand Down
6 changes: 4 additions & 2 deletions src/test/scala/spray/json/AdditionalFormatsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ class AdditionalFormatsSpec extends Specification {
"The lazyFormat wrapper" should {
"enable recursive format definitions" in {
import FooProtocol._
Foo(1, "a", Some(Foo(2, "b", Some(Foo(3, "c") :: Nil)) :: Foo(4, "d") :: Nil)).toJson.toString mustEqual
"""{"id":1,"name":"a","foos":[{"id":2,"name":"b","foos":[{"id":3,"name":"c"}]},{"id":4,"name":"d"}]}"""
val json = Foo(1, "a", Some(Foo(2, "b", Some(Foo(3, "c") :: Nil)) :: Foo(4, "d") :: Nil)).toJson

json mustEqual
"""{"id":1,"name":"a","foos":[{"id":2,"name":"b","foos":[{"id":3,"name":"c"}]},{"id":4,"name":"d"}]}""".parseJson
}
}
}
6 changes: 3 additions & 3 deletions src/test/scala/spray/json/CollectionFormatsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class CollectionFormatsSpec extends Specification with DefaultJsonProtocol {

"The immutableSetFormat" should {
val set = Set(1, 2, 3)
val json = JsArray(JsNumber(1), JsNumber(2), JsNumber(3))
val numbers = Set(JsNumber(1), JsNumber(2), JsNumber(3))
"convert a Set[Int] to a JsArray of JsNumbers" in {
set.toJson mustEqual json
set.toJson.asInstanceOf[JsArray].elements.toSet mustEqual numbers
}
"convert a JsArray of JsNumbers to a Set[Int]" in {
json.convertTo[Set[Int]] mustEqual set
JsArray(numbers.toVector).convertTo[Set[Int]] mustEqual set
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/test/scala/spray/json/JsonParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ class JsonParserSpec extends Specification {
JsonParser(json.prettyPrint.getBytes("UTF-8")) === json
}
"be reentrant" in {
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global

val largeJsonSource = scala.io.Source.fromInputStream(getClass.getResourceAsStream("/test.json")).mkString
import scala.collection.parallel.immutable.ParSeq
ParSeq.fill(20)(largeJsonSource).map(JsonParser(_)).toList.map {
_.asInstanceOf[JsObject].fields("questions").asInstanceOf[JsArray].elements.size
} === List.fill(20)(100)
val list = Await.result(
Future.traverse(List.fill(20)(largeJsonSource))(src => Future(JsonParser(src))),
5.seconds
)
list.map(_.asInstanceOf[JsObject].fields("questions").asInstanceOf[JsArray].elements.size) === List.fill(20)(100)
}

"produce proper error messages" in {
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/spray/json/ProductFormatsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ class ProductFormatsSpec extends Specification {

"A JsonFormat created with `jsonFormat`, for a case class with mangled-name members," should {
import TestProtocol1._
val json = """{"ü$bavf$u56ú$":true,"=><+-*/!@#%^&~?|":1.0,"foo-bar!":42,"-x-":26,"User ID":"Karl"}"""
val json = """{"ü$bavf$u56ú$":true,"=><+-*/!@#%^&~?|":1.0,"foo-bar!":42,"-x-":26,"User ID":"Karl"}""".parseJson
"produce the correct JSON" in {
TestMangled(42, "Karl", true, 26, 1.0f).toJson.compactPrint === json
TestMangled(42, "Karl", true, 26, 1.0f).toJson === json
}
"convert a JsObject to the respective case class instance" in {
json.parseJson.convertTo[TestMangled] === TestMangled(42, "Karl", true, 26, 1.0f)
json.convertTo[TestMangled] === TestMangled(42, "Karl", true, 26, 1.0f)
}
}
}

0 comments on commit 0131537

Please sign in to comment.