Skip to content

WriteHandler incorrectly serializes maps of size 8 to PersistentHashMap instead of PersistentArrayMap #14

Description

@IngridMorstrad

Line 189 in fressian.clj (link) is (if (< (.size kvs) 16), when it should be (if (<= (.size kvs) 16).

Important background knowledge: Clojure uses a PersistentArrayMap as the backing map if the size of the map is 8 or lower, and a PersistentHashMap otherwise.

The line of code above causes a map of size 8 to be deserialized as a PersistentHashMap. This means that when a map of size 8 is serialized, and then deserialized, the type of the map changes. Specifically, it starts off as a PersistentArrayMap, and the deserialization converts it into a PersistentHashMap. This also means that the second serialization (in a series of serialization -> deserialization -> serialization calls) will return a different value from the first one.

I can send a pull request to fix for this, but want to discuss if we should upgrade the fressian version, since making the change without a major version upgrade can cause existing clients to break (since serialization of the map of size 8 will lead to a different value with the change from < to <=).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions