From 66d341439fc3601c8262d5c60449924b01e4283b Mon Sep 17 00:00:00 2001 From: Arjan Zijderveld <5286904+arjanz@users.noreply.github.com> Date: Tue, 8 Apr 2025 11:35:35 +0200 Subject: [PATCH] Map sorting fix --- jamcodec/types.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jamcodec/types.py b/jamcodec/types.py index 7f6f78d..768a04a 100644 --- a/jamcodec/types.py +++ b/jamcodec/types.py @@ -959,8 +959,11 @@ def __init__(self, key_def: JamCodecTypeDef, value_def: JamCodecTypeDef): def encode(self, value: Union[typing.Mapping, list]) -> JamBytes: if isinstance(value, Mapping): - # Sort Map by keys - value = sorted(value.items(), key=lambda x: x[0]) + value = value.items() + + if type(value) is list: + # Sort by first item + value = sorted(value, key=lambda x: x[0]) # Encode length of Vec data = VarInt64.encode(len(value))