Skip to content

Commit 70145a4

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 f7a90e9 commit 70145a4

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
@@ -78,6 +78,7 @@
7878
import org.springframework.util.ClassUtils;
7979
import org.springframework.util.CollectionUtils;
8080
import org.springframework.util.ObjectUtils;
81+
import org.springframework.util.StringUtils;
8182

8283
import com.mongodb.BasicDBList;
8384
import com.mongodb.BasicDBObject;
@@ -206,6 +207,9 @@ public MongoTypeMapper getTypeMapper() {
206207
* any translation but rather reject a {@link Map} with keys containing dots causing the conversion for the entire
207208
* object to fail. If further customization of the translation is needed, have a look at
208209
* {@link #potentiallyEscapeMapKey(String)} as well as {@link #potentiallyUnescapeMapKey(String)}.
210+
* <p>
211+
* {@code mapKeyDotReplacement} is used as-is during replacement operations without further processing (i.e. regex or
212+
* normalization).
209213
*
210214
* @param mapKeyDotReplacement the mapKeyDotReplacement to set. Can be {@literal null}.
211215
*/
@@ -924,7 +928,7 @@ protected String potentiallyEscapeMapKey(String source) {
924928
source));
925929
}
926930

927-
return source.replaceAll("\\.", mapKeyDotReplacement);
931+
return StringUtils.replace(source, ".", mapKeyDotReplacement);
928932
}
929933

930934
/**
@@ -950,7 +954,7 @@ private String potentiallyConvertMapKey(Object key) {
950954
* @param source must not be {@literal null}.
951955
*/
952956
protected String potentiallyUnescapeMapKey(String source) {
953-
return mapKeyDotReplacement == null ? source : source.replaceAll(mapKeyDotReplacement, "\\.");
957+
return mapKeyDotReplacement == null ? source : StringUtils.replace(source, mapKeyDotReplacement, ".");
954958
}
955959

956960
/**

0 commit comments

Comments
 (0)