From 04707ecc270e622611d3c67b74df376bc610f35f Mon Sep 17 00:00:00 2001 From: Christoph Strobl Date: Mon, 15 Feb 2021 09:52:17 +0100 Subject: [PATCH] Preserve order in SetConverter. This commit fixes an issue where the order of elements in a set is not preserved when converting elements of the set. Closes #1969. Original pull request: #1968. --- .../data/redis/connection/convert/SetConverter.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java b/src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java index b01e9adfd..ff2506983 100644 --- a/src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java +++ b/src/main/java/org/springframework/data/redis/connection/convert/SetConverter.java @@ -15,7 +15,6 @@ */ package org.springframework.data.redis.connection.convert; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.Collectors; @@ -24,7 +23,7 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.util.Assert; /** - * Converts a Set of values of one type to a Set of values of another type + * Converts a Set of values of one type to a Set of values of another type preserving item order. * * @author Jennifer Hickey * @author Christoph Strobl @@ -50,9 +49,7 @@ public class SetConverter implements Converter, Set> { */ @Override public Set convert(Set source) { - - return source.stream().map(itemConverter::convert) - .collect(Collectors.toCollection(source instanceof LinkedHashSet ? LinkedHashSet::new : HashSet::new)); + return source.stream().map(itemConverter::convert).collect(Collectors.toCollection(LinkedHashSet::new)); } }