amnaredo / test

0 stars 0 forks source link

Object field order should not matter #90

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

Using the built-in unpicklers, it appears that the order of fields in a JSON string must be exactly as declared in the case class for parsing to succeed. For example, the generated reader for

case class Foo(a: String, b: String)

will fail to parse the JSON string

{ "b": "blah", "a": "blah" }

whereas it will succeed in parsing the JSON string

{ "a": "blah", "b": "blah" }

Switching around the order of fields in the case class declaration does the "opposite", i.e. it will fail to parse the latter string and succeed in parsing the first string.

I would expect both to succeed.

Use case: I'm using an API in which field order is not guaranteed (and the API cannot easily be modified to guarantee the ordering).

EDIT: Oh, yes, this is using uPickle 0.2.5 on ScalaJS.

ID: 36 Original Author: BardurArantsson

amnaredo commented 3 years ago

Hum, trying to reproduce this with the simpler example I've provided it seems to actually work. I guess there's probably something wrong the larger actual code I'm using. I'll just close for now. I'll reopen or recreate if/when I get a real reproducer. Sorry for the noise.

Original Author: BardurArantsson