#2059 Ordered map is unordered after serialization

endragor Thu 15 Nov 2012

map := [:] { ordered = true }
map["key0"] = "value0"
map["key1"] = "value1"

buf := Buf().writeObj(map).flip

deserializedMap := buf.readObj as Map



brian Thu 15 Nov 2012

That is by design since ordered state isn't serializable. One option would be to always use ordered (treemap) implementation in the decoder. It would be a bit slower, but might give more robust results which always match the text deserialized. I'd like to hear some feedback and support for that change before making it though

endragor Thu 15 Nov 2012

Why not add it as a deserialization option?

jodastephen Fri 16 Nov 2012

The test case just looks like a bug to me. "ordered" is a key part of the state and should be serialised.

bedla Mon 28 Jan 2013

I agree with jodastephen :)

SlimerDude Wed 18 Jun 2014

I've just been bit by this.

I was storing some data in a WebSession and was expecting my data to be regurgitated in the same state as it went in. As it stands my map data comes back in a different order than it went in.

You wouldn't expect the values of a list to come back all jumbled up! The same goes for an ordered map.

Could ordered and caseInsensitive be serialised with the map, and be read back first before the data?

brian Wed 18 Jun 2014

Promoted to ticket #2059 and assigned to brian

I think what I finally decided in JSON was to always deserialize maps in order. Its a bit slower, but simplest solution for "just works"

brian Thu 8 Jan 2015

Ticket resolved in 1.0.67

Change fantom deserialization to always use ordered maps to match the behavior in JSON. This doesn't actually maintain the ordered/case insensitive state - that would require redesigning the serialize syntax itself.

SlimerDude Thu 8 Jan 2015

Cool, I saw the LinkedHashMap change!

This doesn't actually maintain the ordered/case insensitive state

Fair enough, could a sentence to this effect be added to the docs, so it doesn't catch people out?

Login or Signup to reply.