Skip to content

Commit

Permalink
Revert "Handled dollar prefixed values for "createOrReplace" Mongo im…
Browse files Browse the repository at this point in the history
…plementa…" (#213)

This reverts commit 9aa8fe6.
  • Loading branch information
suresh-prakash authored Oct 3, 2024
1 parent 9b4eb6e commit a63ab4d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
{
"name": "Mars",
"color": "$Red",
"color": "Red",
"humans_live": "possibly in future",
"tags": {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
{
"name": "Mars",
"color": "$Red",
"color": "Red",
"humans_live": "possibly in future",
"tags": {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.mongodb.BasicDBObject;
import com.mongodb.client.model.ReturnDocument;
import java.io.IOException;
Expand All @@ -37,7 +35,6 @@
public final class MongoUtils {
public static final String FIELD_SEPARATOR = ".";
public static final String PREFIX = "$";
private static final String UNICODE_FOR_FIELD_PREFIX = "\\u0024";
private static final String LITERAL = PREFIX + "literal";
private static final String UNSUPPORTED_OPERATION = "No MongoDB support available for: '%s'";
private static final ObjectMapper MAPPER = new ObjectMapper();
Expand All @@ -57,19 +54,15 @@ public static String encodeKey(final String key) {
return null;
}

return key.replace("\\", "\\\\")
.replace(PREFIX, UNICODE_FOR_FIELD_PREFIX)
.replace(FIELD_SEPARATOR, "\\u002e");
return key.replace("\\", "\\\\").replace(PREFIX, "\\u0024").replace(FIELD_SEPARATOR, "\\u002e");
}

public static String decodeKey(final String key) {
if (key == null) {
return null;
}

return key.replace("\\u002e", FIELD_SEPARATOR)
.replace(UNICODE_FOR_FIELD_PREFIX, PREFIX)
.replace("\\\\", "\\");
return key.replace("\\u002e", FIELD_SEPARATOR).replace("\\u0024", PREFIX).replace("\\\\", "\\");
}

public static String getLastField(final String fieldPath) {
Expand Down Expand Up @@ -106,10 +99,6 @@ public static JsonNode recursiveClone(
JsonNode src,
UnaryOperator<String> function,
final UnaryOperator<ObjectNode> emptyObjectConverter) {
if (src.isTextual()) {
return new TextNode(function.apply(src.asText()));
}

if (!src.isObject()) {
return src;
}
Expand All @@ -124,17 +113,6 @@ public static JsonNode recursiveClone(
if (value.isObject()) {
newValue = recursiveClone(value, function, emptyObjectConverter);
}
if (value.isArray()) {
newValue = new ArrayNode(JsonNodeFactory.instance);
for (int i = 0; i < value.size(); i++) {
final JsonNode elementValue =
recursiveClone(value.get(i), function, emptyObjectConverter);
((ArrayNode) newValue).add(elementValue);
}
}
if (newValue.isTextual()) {
newValue = new TextNode(function.apply(newValue.asText()));
}
tgt.set(newFieldName, newValue);
}
return tgt.isEmpty() ? emptyObjectConverter.apply(tgt) : tgt;
Expand Down

0 comments on commit a63ab4d

Please sign in to comment.