Skip to content

Commit 16bef54

Browse files
committed
Use StringUtils.replace(…) instead of String.replaceAll(…) for mapKeyDotReplacement.
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
1 parent d68a812 commit 16bef54

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/MappingMongoConverter.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import org.springframework.util.ClassUtils;
7676
import org.springframework.util.CollectionUtils;
7777
import org.springframework.util.ObjectUtils;
78+
import org.springframework.util.StringUtils;
7879

7980
import com.mongodb.BasicDBList;
8081
import com.mongodb.BasicDBObject;
@@ -182,6 +183,9 @@ public MongoTypeMapper getTypeMapper() {
182183
* any translation but rather reject a {@link Map} with keys containing dots causing the conversion for the entire
183184
* object to fail. If further customization of the translation is needed, have a look at
184185
* {@link #potentiallyEscapeMapKey(String)} as well as {@link #potentiallyUnescapeMapKey(String)}.
186+
* <p>
187+
* {@code mapKeyDotReplacement} is used as-is during replacement operations without further processing (i.e. regex or
188+
* normalization).
185189
*
186190
* @param mapKeyDotReplacement the mapKeyDotReplacement to set. Can be {@literal null}.
187191
*/
@@ -900,7 +904,7 @@ protected String potentiallyEscapeMapKey(String source) {
900904
source));
901905
}
902906

903-
return source.replaceAll("\\.", mapKeyDotReplacement);
907+
return StringUtils.replace(source, ".", mapKeyDotReplacement);
904908
}
905909

906910
/**
@@ -928,7 +932,7 @@ private String potentiallyConvertMapKey(Object key) {
928932
* @return
929933
*/
930934
protected String potentiallyUnescapeMapKey(String source) {
931-
return mapKeyDotReplacement == null ? source : source.replaceAll(mapKeyDotReplacement, "\\.");
935+
return mapKeyDotReplacement == null ? source : StringUtils.replace(source, mapKeyDotReplacement, ".");
932936
}
933937

934938
/**

0 commit comments

Comments
 (0)