From 70145a4c8656ebd4323cf776ea51b95e8e108872 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 30 Mar 2021 14:29:44 +0200 Subject: [PATCH] =?UTF-8?q?Use=20StringUtils.replace(=E2=80=A6)=20instead?= =?UTF-8?q?=20of=20String.replaceAll(=E2=80=A6)=20for=20mapKeyDotReplaceme?= =?UTF-8?q?nt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now use StringUtils.replace(…) to replace the map key dot in MappingMongoConverter. StringUtils perform a plain search instead of using Regex which improves the overall performance. Closes #3613 --- .../data/mongodb/core/convert/MappingMongoConverter.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java index 1ef9592aa..4a2a7fc15 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java @@ -78,6 +78,7 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; import com.mongodb.BasicDBList; import com.mongodb.BasicDBObject; @@ -206,6 +207,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * any translation but rather reject a {@link Map} with keys containing dots causing the conversion for the entire * object to fail. If further customization of the translation is needed, have a look at * {@link #potentiallyEscapeMapKey(String)} as well as {@link #potentiallyUnescapeMapKey(String)}. + *

+ * {@code mapKeyDotReplacement} is used as-is during replacement operations without further processing (i.e. regex or + * normalization). * * @param mapKeyDotReplacement the mapKeyDotReplacement to set. Can be {@literal null}. */ @@ -924,7 +928,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App source)); } - return source.replaceAll("\\.", mapKeyDotReplacement); + return StringUtils.replace(source, ".", mapKeyDotReplacement); } /** @@ -950,7 +954,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App * @param source must not be {@literal null}. */ protected String potentiallyUnescapeMapKey(String source) { - return mapKeyDotReplacement == null ? source : source.replaceAll(mapKeyDotReplacement, "\\."); + return mapKeyDotReplacement == null ? source : StringUtils.replace(source, mapKeyDotReplacement, "."); } /**