Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ scala:
- 2.11.12
- 2.12.10
- 2.13.1
- 3.1.0

before_install:
- sudo rm -r /usr/local/clang-7.0.0
Expand Down
17 changes: 14 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ lazy val scala210 = "2.10.7"
lazy val scala211 = "2.11.12"
lazy val scala212 = "2.12.10"
lazy val scala213 = "2.13.1"
lazy val scala3 = "3.1.0"

lazy val sprayJson =
crossProject(JVMPlatform, JSPlatform, NativePlatform)
Expand All @@ -29,7 +30,13 @@ lazy val sprayJson =
.enablePlugins(spray.boilerplate.BoilerplatePlugin)
.platformsSettings(JVMPlatform, JSPlatform)(
libraryDependencies ++= {
if (scalaMinorVersion.value >= 11)
if (scalaMajorVersion.value >= 3)
Seq(
("org.specs2" %%% "specs2-core" % "4.5.1" % "test").cross(CrossVersion.for3Use2_13),
("org.specs2" %%% "specs2-scalacheck" % "4.5.1" % "test").cross(CrossVersion.for3Use2_13),
"org.scalacheck" %%% "scalacheck" % "1.15.4" % "test"
)
else if (scalaMinorVersion.value >= 11)
Seq(
"org.specs2" %%% "specs2-core" % "4.5.1" % "test",
"org.specs2" %%% "specs2-scalacheck" % "4.5.1" % "test",
Expand All @@ -45,13 +52,16 @@ lazy val sprayJson =
)
.configurePlatforms(JVMPlatform)(_.enablePlugins(SbtOsgi))
.jvmSettings(
crossScalaVersions := Seq(scala213, scala212, scala211, scala210),
crossScalaVersions := Seq(scala3, scala213, scala212, scala211, scala210),
OsgiKeys.exportPackage := Seq("""spray.json.*;version="${Bundle-Version}""""),
OsgiKeys.importPackage := Seq("""scala.*;version="$<range;[==,=+);%s>"""".format(scalaVersion.value)),
OsgiKeys.importPackage ++= Seq("""spray.json;version="${Bundle-Version}"""", "*"),
OsgiKeys.additionalHeaders := Map("-removeheaders" -> "Include-Resource,Private-Package"),
ThisBuild / mimaReportSignatureProblems := true,
mimaPreviousArtifacts := {
if (scalaMinorVersion.value == 13) Set("io.spray" %% "spray-json" % "1.3.5")
if (scalaMajorVersion.value == 3) Set.empty
else if (scalaMinorVersion.value == 13) Set("io.spray" %% "spray-json" % "1.3.5")
else if (scalaMinorVersion.value == 10) Set.empty
else Set("1.3.2", "1.3.3", "1.3.4", "1.3.5").map { v => "io.spray" %% "spray-json" % v }
},
mimaBinaryIssueFilters := Seq(
Expand Down Expand Up @@ -100,4 +110,5 @@ lazy val root = (project in file("."))
scalaVersion := scala212,
)

def scalaMajorVersion: Def.Initialize[Long] = Def.setting { CrossVersion.partialVersion(scalaVersion.value).get._1 }
def scalaMinorVersion: Def.Initialize[Long] = Def.setting { CrossVersion.partialVersion(scalaVersion.value).get._2 }
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.4
sbt.version=1.5.4
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ addSbtPlugin("io.spray" % "sbt-boilerplate" % "0.6.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.5")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.6.1")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "0.6.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package spray.json

import scala.reflect.{ classTag, ClassTag }

trait ProductFormatsInstances { self: ProductFormats with StandardFormats =>
trait ProductFormatsInstances { self: ProductFormats with StandardFormats with AdditionalFormats =>
[# // Case classes with 1 parameters

/**
Expand Down
6 changes: 3 additions & 3 deletions spray-json/jvm/src/main/scala/spray/json/ProductFormats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import scala.reflect.ClassTag
* (especially case classes)
*/
trait ProductFormats extends ProductFormatsInstances {
this: StandardFormats =>
this: StandardFormats with AdditionalFormats =>

def jsonFormatN[T](construct: () => T): RootJsonFormat[T] =
new RootJsonFormat[T] {
Expand Down Expand Up @@ -74,7 +74,7 @@ trait ProductFormats extends ProductFormatsInstances {
_.getName.drop("copy$default$".length).takeWhile(_ != '(').toInt)
val fields = clazz.getDeclaredFields.filterNot { f =>
import Modifier._
(f.getModifiers & (TRANSIENT | STATIC | 0x1000 /* SYNTHETIC*/ )) > 0
(f.getModifiers & (TRANSIENT | STATIC | 0x1000 /* SYNTHETIC*/ )) > 0 || f.getName.endsWith("$outer")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As scala/scala3#14083 was fixed in Scala 3.1.2, if you update the Scala 3 version this OR is no longer needed.

}
if (copyDefaultMethods.length != fields.length)
sys.error("Case class " + clazz.getName + " declares additional fields")
Expand Down Expand Up @@ -145,7 +145,7 @@ object ProductFormats {
* optional members as `None`.)
*/
trait NullOptions extends ProductFormats {
this: StandardFormats =>
this: StandardFormats with AdditionalFormats =>

override protected def productElement2Field[T](fieldName: String, p: Product, ix: Int, rest: List[JsField])(implicit writer: JsonWriter[T]) = {
val value = p.productElement(ix).asInstanceOf[T]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class JsonParserSpecJvm extends Specification {
queue.peek
}

val i: Int = Iterator.iterate(1)(1+).indexWhere(depth => probe(depth, maxDepth = 1000) contains "stackoverflow")
// Explicit type needed to compile on Scala 2.10, can be inlined later
def inc(i: Int): Int = 1 + i
val i: Int = Iterator.iterate(1)(inc).indexWhere(depth => probe(depth, maxDepth = 1000) contains "stackoverflow")
println(s"Overflowing stack at $i which means we need about ${stackSize / i} bytes per recursive call")

val maxDepth = i / 4 // should give lots of room
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class ProductFormatsSpec extends Specification {

trait TestProtocol {
this: DefaultJsonProtocol =>
implicit val test0Format = jsonFormatN(Test0)
implicit val test2Format = jsonFormatN(Test2.apply _)
implicit def test3Format[A: JsonFormat, B: JsonFormat] = jsonFormatN(Test3[A, B] _)
implicit def test4Format = jsonFormatN(Test4.apply _)
implicit def testTransientFormat = jsonFormatN(TestTransient)
implicit def testStaticFormat = jsonFormatN(TestStatic)
implicit def testMangledFormat = jsonFormatN(TestMangled)
implicit val test0Format: JsonFormat[Test0] = jsonFormatN(Test0.apply _)
implicit val test2Format: JsonFormat[Test2] = jsonFormatN(Test2.apply _)
implicit def test3Format[A: JsonFormat, B: JsonFormat]: JsonFormat[Test3[A, B]] = jsonFormatN(Test3.apply[A, B] _)
implicit def test4Format: JsonFormat[Test4] = jsonFormatN(Test4.apply _)
implicit def testTransientFormat: JsonFormat[TestTransient] = jsonFormatN(TestTransient.apply _)
implicit def testStaticFormat: JsonFormat[TestStatic] = jsonFormatN(TestStatic.apply _)
implicit def testMangledFormat: JsonFormat[TestMangled] = jsonFormatN(TestMangled.apply _)
}
object TestProtocol1 extends DefaultJsonProtocol with TestProtocol
object TestProtocol2 extends DefaultJsonProtocol with TestProtocol with NullOptions
Expand Down Expand Up @@ -108,7 +108,7 @@ class ProductFormatsSpec extends Specification {
}
"A JsonFormat for a case class with 18 parameters and created with `jsonFormat`" should {
object Test18Protocol extends DefaultJsonProtocol {
implicit val test18Format = jsonFormatN(Test18.apply _)
implicit val test18Format: JsonFormat[Test18] = jsonFormatN(Test18.apply _)
}
case class Test18(
a1: String,
Expand Down Expand Up @@ -147,7 +147,7 @@ class ProductFormatsSpec extends Specification {
"support the jsonFormatN syntax" in {
case class Box[A](a: A)
object BoxProtocol extends DefaultJsonProtocol {
implicit val boxFormat = jsonFormatN(Box[Int] _)
implicit val boxFormat: JsonFormat[Box[Int]] = jsonFormatN(Box[Int] _)
}
import BoxProtocol._
Box(42).toJson === JsObject(Map("a" -> JsNumber(42)))
Expand Down
2 changes: 1 addition & 1 deletion spray-json/jvm/src/test/scala/spray/json/ReadmeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ReadmeSpec extends Specification {
"The case class example" should {
"behave as expected" in {
object MyJsonProtocol extends DefaultJsonProtocol {
implicit val colorFormat = jsonFormatN(Color.apply _)
implicit val colorFormat: JsonFormat[Color] = jsonFormatN(Color.apply _)
}
import MyJsonProtocol._
color.toJson.convertTo[Color] mustEqual color
Expand Down
2 changes: 1 addition & 1 deletion spray-json/shared/src/main/scala/spray/json/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ package object json {
def jsonReader[T](implicit reader: JsonReader[T]) = reader
def jsonWriter[T](implicit writer: JsonWriter[T]) = writer

implicit def enrichAny[T](any: T) = new RichAny(any)
implicit def enrichAny[T](any: T): RichAny[T] = new RichAny(any)
def enrichString(string: String) = new RichString(string)
implicit class RichWithInput[I](any: I)(implicit i: Input[I]) {
def parseJson: JsValue = json.parseJson(any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AdditionalFormatsSpec extends Specification with RoundTripSpecBase {
case class Container[A](inner: Option[A])

object ReaderProtocol extends DefaultJsonProtocol {
implicit def containerReader[T: JsonFormat] = lift {
implicit def containerReader[T: JsonFormat]: JsonFormat[Container[T]] = lift {
new JsonReader[Container[T]] {
def read(value: JsValue) = value match {
case JsObject(fields) if fields.contains("content") => Container(Some(jsonReader[T].read(fields("content"))))
Expand All @@ -34,7 +34,7 @@ class AdditionalFormatsSpec extends Specification with RoundTripSpecBase {
}

object WriterProtocol extends DefaultJsonProtocol {
implicit def containerWriter[T: JsonFormat] = lift {
implicit def containerWriter[T: JsonFormat]: JsonFormat[Container[T]] = lift {
new JsonWriter[Container[T]] {
def write(obj: Container[T]) = JsObject("content" -> obj.inner.toJson)
}
Expand All @@ -58,7 +58,7 @@ class AdditionalFormatsSpec extends Specification with RoundTripSpecBase {
case class Foo(id: Long, name: String, foos: Option[List[Foo]] = None)

object FooProtocol extends DefaultJsonProtocol {
implicit val fooProtocol: JsonFormat[Foo] = lazyFormat(jsonFormat(Foo, "id", "name", "foos"))
implicit val fooProtocol: JsonFormat[Foo] = lazyFormat(jsonFormat(Foo.apply, "id", "name", "foos"))
}

"The lazyFormat wrapper" should {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CustomFormatSpec extends Specification with DefaultJsonProtocol {

case class MyType(name: String, value: Int)

implicit val MyTypeProtocol = new RootJsonFormat[MyType] {
implicit val MyTypeProtocol: JsonFormat[MyType] = new JsonFormat[MyType] {
def read(json: JsValue) = {
json.asJsObject.getFields("name", "value") match {
case Seq(JsString(name), JsNumber(value)) => MyType(name, value.toInt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ abstract class JsonParserSpec[T: Input](inputFromString: String => T) extends Sp

def nanoBench(block: => Unit): Long = {
// great microbenchmark (the comment must be kept, otherwise it's not true)
val f = block _
val f = () => block

// warmup
(1 to 10).foreach(_ => f())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PrettyPrinterSpec extends Specification {
"""{
| "Boolean no": false,
| "Boolean yes":true,
| "Unic\u00f8de" : "Long string with newline\nescape",
| "Unicøde" : "Long string with newline\nescape",
| "key with \"quotes\"" : "string",
| "key with spaces": null,
| "number": -1.2323424E-5,
Expand All @@ -48,7 +48,7 @@ class PrettyPrinterSpec extends Specification {
"""{
| "Boolean no": false,
| "Boolean yes": true,
| "Unic\u00f8de": "Long string with newline\nescape",
| "Unicøde": "Long string with newline\nescape",
| "key with \"quotes\"": "string",
| "key with spaces": null,
| "number": -0.000012323424,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SortedPrinterSpec extends Specification {
"print a more complicated JsObject nicely aligned with fields sorted" in {
val obj =
"""{
| "Unic\u00f8de" : "Long string with newline\nescape",
| "Unicøde" : "Long string with newline\nescape",
| "Boolean no": false,
| "number": -1.2323424E-5,
| "key with \"quotes\"" : "string",
Expand All @@ -43,7 +43,7 @@ class SortedPrinterSpec extends Specification {
"""{
| "Boolean no": false,
| "Boolean yes": true,
| "Unic\u00f8de": "Long string with newline\nescape",
| "Unicøde": "Long string with newline\nescape",
| "key with \"quotes\"": "string",
| "key with spaces": null,
| "number": -0.000012323424,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ class StandardFormatsSpec extends Specification with DefaultJsonProtocol {
"be automatically provided from JsonFormat" in {
trait X
implicit def format: JsonFormat[X] = ???
implicit def reader = implicitly[JsonReader[X]]
implicit def reader: JsonReader[X] = implicitly[JsonReader[X]]
success
}
}
"JsonWriter" should {
"be automatically provided from JsonFormat" in {
trait X
implicit def format: JsonFormat[X] = ???
implicit def reader = implicitly[JsonWriter[X]]
implicit def reader: JsonWriter[X] = implicitly[JsonWriter[X]]
success
}
}
Expand Down