DictionaryDecoder: Return a LinkedHashMap in serialized order.
Guarantees a predictable iteration order in the returned map. Once we
move to Java 21 as a baseline, DictionaryDecoder can declare
SequencedMap<K, V> as its entity type.
Change-Id: I8dc52ec1690e85bec27419417d68e447f65398ee
diff --git a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java
index f605b09..9362487 100644
--- a/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java
+++ b/jgvariant-core/src/main/java/eu/mulk/jgvariant/core/Decoder.java
@@ -22,13 +22,8 @@
import java.nio.channels.Channels;
import java.nio.charset.Charset;
import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
@@ -485,7 +480,11 @@
@Override
public @NotNull Map<K, V> decode(ByteBuffer byteSlice) {
List<Map.Entry<K, V>> entries = entryArrayDecoder.decode(byteSlice);
- return entries.stream().collect(toMap(Entry::getKey, Entry::getValue));
+ Map<K, V> result = new LinkedHashMap<>();
+ for (var entry : entries) {
+ result.put(entry.getKey(), entry.getValue());
+ }
+ return result;
}
@Override