tebru / gson-php

Gson implemented in PHP
Other
151 stars 18 forks source link

[QUESTION] Does the order of elements in associative array is guaranteed between encode/decode? #36

Closed tomekit closed 5 years ago

tomekit commented 5 years ago

I've got a specific use case where I am calculating checksum/hash for the object contents based on the serialization output. Does GSON preserve the order of elements in an associative array? For instance JSON doesn't support that. I've found many references that GSON maintains that order correctly, however I can't find any official info about that. Hope you can help to answer that. Thanks !

natebrunette commented 5 years ago

Yes, it does.

tomekit commented 5 years ago

Thank you for your response. Is this behaviour documented either in the original: https://github.com/google/gson or in this repository? Basically this is something I am going to rely on, looking for more assurance, especially that the is pretty lots of confusion in this topic.

natebrunette commented 5 years ago

It's not explicitly documented, however we just read the json in the order we receive it. Feel free to run some tests yourself to verify the behavior.