Skip to content

Commit 1014817

Browse files
Polishing.
Original Pull Request: #4822
1 parent 486bf84 commit 1014817

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/BindableMongoExpression.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public BindableMongoExpression(String expression, @Nullable CodecRegistryProvide
8181

8282
Assert.notNull(expression, "Expression must not be null");
8383

84-
this.expressionString = expression.trim();
84+
this.expressionString = expression;
8585
this.codecRegistryProvider = codecRegistryProvider;
8686
this.args = args;
8787
this.target = Lazy.of(this::parse);
@@ -139,10 +139,11 @@ private Document parse() {
139139

140140
private static String wrapJsonIfNecessary(String json) {
141141

142-
if (StringUtils.hasText(json) && (json.startsWith("{") && json.endsWith("}"))) {
142+
if(!StringUtils.hasText(json)) {
143143
return json;
144144
}
145145

146-
return "{" + json + "}";
146+
String raw = json.trim();
147+
return (raw.startsWith("{") && raw.endsWith("}")) ? raw : "{%s}".formatted(raw);
147148
}
148149
}

0 commit comments

Comments
 (0)