diff options
author | Dan Brown <jdanbrown@gmail.com> | 2013-04-22 18:54:57 -0400 |
---|---|---|
committer | Dan Brown <jdanbrown@gmail.com> | 2013-04-22 19:07:21 -0400 |
commit | eacfb581fd89b0c9b3118e91e8b23db3b3ef0032 (patch) | |
tree | 760a89cefe5e5948dee19501b03335bcc3290828 /src/test/scala/spray/json | |
parent | 522c29d22a775ea7e6a8cd5fc2a50123bd94d66b (diff) | |
download | spray-json-eacfb581fd89b0c9b3118e91e8b23db3b3ef0032.tar.gz spray-json-eacfb581fd89b0c9b3118e91e8b23db3b3ef0032.tar.bz2 spray-json-eacfb581fd89b0c9b3118e91e8b23db3b3ef0032.zip |
Fix extractFieldNames: Ignore transient fields
Diffstat (limited to 'src/test/scala/spray/json')
-rw-r--r-- | src/test/scala/spray/json/ProductFormatsSpec.scala | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/scala/spray/json/ProductFormatsSpec.scala b/src/test/scala/spray/json/ProductFormatsSpec.scala index ec9d65f..5a07b4f 100644 --- a/src/test/scala/spray/json/ProductFormatsSpec.scala +++ b/src/test/scala/spray/json/ProductFormatsSpec.scala @@ -22,11 +22,15 @@ class ProductFormatsSpec extends Specification { case class Test2(a: Int, b: Option[Double]) case class Test3[A, B](as: List[A], bs: List[B]) + case class TestTransient(a: Int, b: Option[Double]) { + @transient var c = false + } 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) } object TestProtocol1 extends DefaultJsonProtocol with TestProtocol object TestProtocol2 extends DefaultJsonProtocol with TestProtocol with NullOptions @@ -95,4 +99,16 @@ class ProductFormatsSpec extends Specification { } } + "A JsonFormat for a case class with transient fields and created with `jsonFormat`" should { + import TestProtocol1._ + val obj = TestTransient(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[TestTransient] mustEqual obj + } + } + } |