You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fory.apache.org by "pferraro (via GitHub)" <gi...@apache.org> on 2026/08/21 21:48:49 UTC

[I] Access ordered LinkedHashMap not preserved following deserialisation. [fory]

pferraro opened a new issue, #3965:
URL: https://github.com/apache/fory/issues/3965

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/fory/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
   
   ```java
   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!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] Access ordered LinkedHashMap not preserved following deserialisation. [fory]

Posted by "mohithvardhan002 (via GitHub)" <gi...@apache.org>.
mohithvardhan002 commented on issue #3965:
URL: https://github.com/apache/fory/issues/3965#issuecomment-6021445916

   Hi @chaokunyang, I’d like to work on this issue and submit a PR for it.
   
   I understand that preserving `LinkedHashMap` access order requires updating the wire format for Fory 2.0, as discussed above. I’ll first inspect the existing `MapSerializer`/`LinkedHashMap` serialization path and add regression tests before implementing the fix.
   
   Please let me know if there are any additional considerations I should keep in mind.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] Access ordered LinkedHashMap not preserved following deserialisation. [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #3965:
URL: https://github.com/apache/fory/issues/3965#issuecomment-5384202417

   Thanks for reporting this issue, the fix is not complex, but it will break exising wire format. 
   
   Currently, you can register a serializer for LinkedHashMap by:
   
   ```java
   public static final class LinkedHashMapSerializer extends MapSerializer<LinkedHashMap> {
     private static final FieldAccessor ACCESS_ORDER_ACCESSOR =
         FieldAccessor.createAccessor(
             ReflectionUtils.getDeclaredField(LinkedHashMap.class, "accessOrder"));
   
     public LinkedHashMapSerializer(TypeResolver typeResolver) {
       super(typeResolver, LinkedHashMap.class, true);
     }
   
     @Override
     public Map onMapWrite(WriteContext writeContext, LinkedHashMap value) {
       Map map = super.onMapWrite(writeContext, value);
       if (!config.isXlang()) {
         writeContext.getBuffer().writeBoolean(ACCESS_ORDER_ACCESSOR.getBoolean(value));
       }
       return map;
     }
   
     @Override
     public LinkedHashMap newMap(
         ReadContext readContext, boolean entryReadAlwaysAdvances) {
       MemoryBuffer buffer = readContext.getBuffer();
       int numElements = readMapSize(readContext, buffer, entryReadAlwaysAdvances);
       setNumElements(numElements);
   
       boolean accessOrder = !config.isXlang() && buffer.readBoolean();
       LinkedHashMap hashMap = new LinkedHashMap(numElements, 0.75f, accessOrder);
       readContext.reference(hashMap);
       return hashMap;
     }
   
     @Override
     public Map newMap(Map map) {
       boolean accessOrder = ACCESS_ORDER_ACCESSOR.getBoolean(map);
       return new LinkedHashMap(map.size(), 0.75f, accessOrder);
     }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org


Re: [I] Access ordered LinkedHashMap not preserved following deserialisation. [fory]

Posted by "chaokunyang (via GitHub)" <gi...@apache.org>.
chaokunyang commented on issue #3965:
URL: https://github.com/apache/fory/issues/3965#issuecomment-5384208798

   We will update the wire format for this in fory 2.0


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fory.apache.org
For additional commands, e-mail: commits-help@fory.apache.org