Is the JSON serializer deterministic? i.e. if two ...
# serialization
r
Is the JSON serializer deterministic? i.e. if two input data classes are equal, will it always produce the same output, regardless of where and when? I think we can assume the same version of kotlinx-serialization is always used.
d
The same compiled binary, yes. Stability issue would come from the Kotlin compiler as it does not guarantee field order iirc.
r
Probably safest to apply a canonicalization to it. https://github.com/erdtman/java-json-canonicalization seems like it will work.
e
Kotlin serialization guarantees the same field order as in the program. The differences may come only between different versions of libs, if serialization format has a leeway in how things can be encoded.
👍 1
However, the underlying data may be non-deterministic. E.g. a
HashMap
has no defined order of entries.
🆗 1