spray-json icon indicating copy to clipboard operation
spray-json copied to clipboard

case class with dashes incorrectly deserialized

Open maspwr opened this issue 10 years ago • 4 comments

I'm actually not sure what is going on here yet, but it appears as though vals with matching prefixes get deserialized in an incorrect order.

scala> case class Foo(bar: String, dummy: String, `bar-extension`: String)
defined class Foo

scala> implicit val fooFormat: JsonFormat[Foo] = jsonFormat3(Foo)
fooFormat: spray.json.JsonFormat[Foo] = spray.json.ProductFormatsInstances$$anon$3@3e219936

scala> val fooString = """{"bar": "param1", "dummy": "param2", "bar-extension": "param3"}"""
fooString: String = {"bar": "param1", "dummy": "param2", "bar-extension": "param3"}

scala> fooString.parseJson.convertTo[Foo]
res7: Foo = Foo(param1,param3,param2)

maspwr avatar Feb 09 '15 20:02 maspwr

Whoops, that looks like a bad bug! Thanks for reporting! We will have to look into this.

sirthias avatar Feb 10 '15 15:02 sirthias

This seems to be a scala bug.

case class Data(a: String, b: String, `a-some`: String)
val m = Data("1", "2", "3")
assert(m.productIterator.mkString(", ") == "1, 2, 3")

Result: "1, [3, 2]" did not equal "1, [2, 3]"

SimonAdameit avatar Mar 19 '15 16:03 SimonAdameit

@SimonAdameit interesting find. Have you looked for it at http://issues.scala-lang.org?

jrudolph avatar Mar 19 '15 17:03 jrudolph

Thanks, @SimonAdameit for raising this on the Scala mailing. FTR here is the Scala issue and the ML post:

https://issues.scala-lang.org/browse/SI-8831 https://groups.google.com/d/topic/scala-language/vDhcDEF2Rtw/discussion

jrudolph avatar Mar 19 '15 19:03 jrudolph