Skip to content

Commit

Permalink
GH-182 Return mutable instances of empty lists and maps (Fix #182)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzikoysk committed Jun 19, 2024
1 parent 5e32a9f commit 51347de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,7 +44,7 @@ public Result<List<Object>, 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,7 +90,7 @@ public Result<Map<Object, Object>, 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));
}

Expand Down

0 comments on commit 51347de

Please sign in to comment.