As I understand the JSON spec, there is no order d...
# serialization
p
As I understand the JSON spec, there is no order dependence on fields on a JSON object:
{"foo":"fooValue","fee":"feeValue"}
and `{"fee":"feeValue","foo":"fooValue"}`should deserialize to the same object. But this is apparently not the case with KXS. Is there some fine print that says JSON implementors can do pretty much what they want or is this a bug of some sort? My assumption is the former so that means transforming incoming JSON to a correct order. Any chance I have this assumption wrong?
v
Order shouldn't be important and KXS should handle it well afair.
👍 2
Yes, it does, why do you think it does not?
h
Yeah I just did a simple test, that is confirming order doesn't matter in this (as expected)
Copy code
@Serializable
data class TestData(val fee:String, val foo:String)
...

val json1 = "{\"fee\":\"feeValue\",\"foo\":\"fooValue\"}"
val json2 = "{\"foo\":\"fooValue\",\"fee\":\"feeValue\"}"
val obj1 = decodeFromString(TestData.serializer(), json1)
val obj2 = decodeFromString(TestData.serializer(), json2)
println(obj1)
println(obj2)
println(obj1 == obj2)
p
Good to know. I’ll drill into my test case and figure out what is amiss. Thanks for the feedback.
v
Maybe you did not have a data class and thus no equals implementation?
p
Yes, I did not have a data class. I will try that.
Turns out that I had another problem entirely (with encoding, not decoding). When I fixed that I discovered that a data class was not required, fwiw.
👌 2