From 51347dea220df0f2a945c3a3f1809c11516f8135 Mon Sep 17 00:00:00 2001 From: dzikoysk Date: Wed, 19 Jun 2024 23:53:56 +0200 Subject: [PATCH] GH-182 Return mutable instances of empty lists and maps (Fix #182) --- .../net/dzikoysk/cdn/serdes/composers/ListComposer.java | 4 +++- .../net/dzikoysk/cdn/serdes/composers/MapComposer.java | 8 +++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cdn/src/main/java/net/dzikoysk/cdn/serdes/composers/ListComposer.java b/cdn/src/main/java/net/dzikoysk/cdn/serdes/composers/ListComposer.java index b37c705..f1a3890 100644 --- a/cdn/src/main/java/net/dzikoysk/cdn/serdes/composers/ListComposer.java +++ b/cdn/src/main/java/net/dzikoysk/cdn/serdes/composers/ListComposer.java @@ -26,6 +26,8 @@ import net.dzikoysk.cdn.reflect.TargetType; import panda.std.Result; import panda.std.stream.PandaStream; + +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -42,7 +44,7 @@ public Result, Exception> deserialize(CdnSettings settings, Element Entry entry = (Entry) source; return CdnUtils.destringify(entry.getPieceValue()).trim().endsWith("[]") - ? ok(Collections.emptyList()) + ? ok(new ArrayList<>()) : error(new UnsupportedOperationException("Cannot deserialize list of " + entry)); } diff --git a/cdn/src/main/java/net/dzikoysk/cdn/serdes/composers/MapComposer.java b/cdn/src/main/java/net/dzikoysk/cdn/serdes/composers/MapComposer.java index 1d34b05..8cd9b96 100644 --- a/cdn/src/main/java/net/dzikoysk/cdn/serdes/composers/MapComposer.java +++ b/cdn/src/main/java/net/dzikoysk/cdn/serdes/composers/MapComposer.java @@ -30,10 +30,8 @@ import panda.std.Result; import panda.std.stream.PandaStream; import panda.utilities.ObjectUtils; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; + +import java.util.*; import java.util.function.Function; import static net.dzikoysk.cdn.module.standard.StandardOperators.OBJECT_SEPARATOR; @@ -92,7 +90,7 @@ public Result, Exception> deserialize(CdnSettings settings, String value = CdnUtils.destringify(entry.getPieceValue()); return value.equals("[]") - ? ok(Collections.emptyMap()) + ? ok(new HashMap<>()) : error(new CdnException("Cannot deserialize map of " + value)); }