Skip to content

Access ordered LinkedHashMap not preserved following deserialisation. #3965

Description

@pferraro

Search before asking

  • I had searched in the issues and found no similar issues.

Version

A serialised LinkedHashMap that was constructed to use access order (as opposed to insertion order), will lose this characteristic following deserialisation.

Component(s)

Java

Minimal reproduce step

Fory fory = Fory.builder().withLanguage(Language.JAVA).build();
LinkedHashMap<Integer, Integer> map = new LinkedHashMap<>(16, 0.75, true);
map.put(1, 1);
map.put(2, ");
map.put(3, 3);
map.put(4, 4);
LinkedHashMap<Integer, Integer> deserialised = (LinkedHashMap<Integer, Integer>) fory.deserialize(fory.serialize(map));

// This passes, as expected
assertEquals(map, deserialised);

// Modify access order
assertEquals(2, map.get(2));
assertEquals(4, map.get(4));
assertEquals(1, map.get(1));
assertEquals(3, map.get(3));

assertEquals(2, deserialised.get(2));
assertEquals(4, deserialised.get(4));
assertEquals(1, deserialised.get(1));
assertEquals(3, deserialised.get(3));

// This fails, since access order was not preserved
assertEquals(deserialised.values().iterator().next(), map.values().iterator().next());

What did you expect to see?

The last assertion should have succeeded (as it would when following Java serialization).

What did you see instead?

The last assertion fails.

Anything Else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions