summaryrefslogtreecommitdiff
path: root/src/test/scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/scala')
-rw-r--r--src/test/scala/spray/json/ProductFormatsSpec.scala15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/scala/spray/json/ProductFormatsSpec.scala b/src/test/scala/spray/json/ProductFormatsSpec.scala
index c969a6f..8e3390d 100644
--- a/src/test/scala/spray/json/ProductFormatsSpec.scala
+++ b/src/test/scala/spray/json/ProductFormatsSpec.scala
@@ -25,12 +25,15 @@ class ProductFormatsSpec extends Specification {
case class TestTransient(a: Int, b: Option[Double]) {
@transient var c = false
}
+ @SerialVersionUID(1L) // SerialVersionUID adds a static field to the case class
+ case class TestStatic(a: Int, b: Option[Double])
trait TestProtocol {
this: DefaultJsonProtocol =>
implicit val test2Format = jsonFormat2(Test2)
implicit def test3Format[A: JsonFormat, B: JsonFormat] = jsonFormat2(Test3.apply[A, B])
implicit def testTransientFormat = jsonFormat2(TestTransient)
+ implicit def testStaticFormat = jsonFormat2(TestStatic)
}
object TestProtocol1 extends DefaultJsonProtocol with TestProtocol
object TestProtocol2 extends DefaultJsonProtocol with TestProtocol with NullOptions
@@ -147,4 +150,16 @@ class ProductFormatsSpec extends Specification {
}
}
+ "A JsonFormat for a case class with static fields and created with `jsonFormat`" should {
+ import TestProtocol1._
+ val obj = TestStatic(42, Some(4.2))
+ val json = JsObject("a" -> JsNumber(42), "b" -> JsNumber(4.2))
+ "convert to a respective JsObject" in {
+ obj.toJson mustEqual json
+ }
+ "convert a JsObject to the respective case class instance" in {
+ json.convertTo[TestStatic] mustEqual obj
+ }
+ }
+
}