diff options
-rw-r--r-- | src/main/scala/spray/json/ProductFormats.scala | 3 | ||||
-rw-r--r-- | src/test/scala/spray/json/ProductFormatsSpec.scala | 10 |
2 files changed, 7 insertions, 6 deletions
diff --git a/src/main/scala/spray/json/ProductFormats.scala b/src/main/scala/spray/json/ProductFormats.scala index b1aac8e..7d6c63e 100644 --- a/src/main/scala/spray/json/ProductFormats.scala +++ b/src/main/scala/spray/json/ProductFormats.scala @@ -72,7 +72,8 @@ trait ProductFormats extends ProductFormatsInstances { val copyDefaultMethods = clazz.getMethods.filter(_.getName.startsWith("copy$default$")).sortBy( _.getName.drop("copy$default$".length).takeWhile(_ != '(').toInt) val fields = clazz.getDeclaredFields.filterNot { f => - f.getName.startsWith("$") || Modifier.isTransient(f.getModifiers) || Modifier.isStatic(f.getModifiers) + import Modifier._ + (f.getModifiers & (TRANSIENT | STATIC | 0x1000 /* SYNTHETIC*/)) > 0 } if (copyDefaultMethods.length != fields.length) sys.error("Case class " + clazz.getName + " declares additional fields") diff --git a/src/test/scala/spray/json/ProductFormatsSpec.scala b/src/test/scala/spray/json/ProductFormatsSpec.scala index ebfcec9..c218a9d 100644 --- a/src/test/scala/spray/json/ProductFormatsSpec.scala +++ b/src/test/scala/spray/json/ProductFormatsSpec.scala @@ -29,7 +29,7 @@ class ProductFormatsSpec extends Specification { } @SerialVersionUID(1L) // SerialVersionUID adds a static field to the case class case class TestStatic(a: Int, b: Option[Double]) - case class TestMangled(`foo-bar!`: Int, `User ID`: String, `üt$bavef$u56úrógép`: Boolean) + case class TestMangled(`foo-bar!`: Int, `User ID`: String, `üt$bavef$u56úrógép`: Boolean, `-x-`: Int) trait TestProtocol { this: DefaultJsonProtocol => @@ -39,7 +39,7 @@ class ProductFormatsSpec extends Specification { implicit def test4Format = jsonFormat1(Test4) implicit def testTransientFormat = jsonFormat2(TestTransient) implicit def testStaticFormat = jsonFormat2(TestStatic) - implicit def testMangledFormat = jsonFormat3(TestMangled) + implicit def testMangledFormat = jsonFormat4(TestMangled) } object TestProtocol1 extends DefaultJsonProtocol with TestProtocol object TestProtocol2 extends DefaultJsonProtocol with TestProtocol with NullOptions @@ -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 = """{"foo-bar!":42,"User ID":"Karl","üt$bavef$u56úrógép":true}""" + val json = """{"foo-bar!":42,"User ID":"Karl","üt$bavef$u56úrógép":true,"-x-":26}""" "produce the correct JSON" in { - TestMangled(42, "Karl", true).toJson.compactPrint === json + TestMangled(42, "Karl", true, 26).toJson.compactPrint === json } "convert a JsObject to the respective case class instance" in { - json.parseJson.convertTo[TestMangled] === TestMangled(42, "Karl", true) + json.parseJson.convertTo[TestMangled] === TestMangled(42, "Karl", true, 26) } } } |