1414import com .fasterxml .jackson .core .JsonProcessingException ;
1515import com .fasterxml .jackson .databind .JsonNode ;
1616import com .fasterxml .jackson .databind .ObjectMapper ;
17- import com .fasterxml .jackson .databind .node .ArrayNode ;
1817import com .fasterxml .jackson .databind .node .JsonNodeFactory ;
1918import com .fasterxml .jackson .databind .node .ObjectNode ;
20- import com .fasterxml .jackson .databind .node .TextNode ;
2119import com .mongodb .BasicDBObject ;
2220import com .mongodb .client .model .ReturnDocument ;
2321import java .io .IOException ;
3735public final class MongoUtils {
3836 public static final String FIELD_SEPARATOR = "." ;
3937 public static final String PREFIX = "$" ;
40- private static final String UNICODE_FOR_FIELD_PREFIX = "\\ u0024" ;
4138 private static final String LITERAL = PREFIX + "literal" ;
4239 private static final String UNSUPPORTED_OPERATION = "No MongoDB support available for: '%s'" ;
4340 private static final ObjectMapper MAPPER = new ObjectMapper ();
@@ -57,19 +54,15 @@ public static String encodeKey(final String key) {
5754 return null ;
5855 }
5956
60- return key .replace ("\\ " , "\\ \\ " )
61- .replace (PREFIX , UNICODE_FOR_FIELD_PREFIX )
62- .replace (FIELD_SEPARATOR , "\\ u002e" );
57+ return key .replace ("\\ " , "\\ \\ " ).replace (PREFIX , "\\ u0024" ).replace (FIELD_SEPARATOR , "\\ u002e" );
6358 }
6459
6560 public static String decodeKey (final String key ) {
6661 if (key == null ) {
6762 return null ;
6863 }
6964
70- return key .replace ("\\ u002e" , FIELD_SEPARATOR )
71- .replace (UNICODE_FOR_FIELD_PREFIX , PREFIX )
72- .replace ("\\ \\ " , "\\ " );
65+ return key .replace ("\\ u002e" , FIELD_SEPARATOR ).replace ("\\ u0024" , PREFIX ).replace ("\\ \\ " , "\\ " );
7366 }
7467
7568 public static String getLastField (final String fieldPath ) {
@@ -106,10 +99,6 @@ public static JsonNode recursiveClone(
10699 JsonNode src ,
107100 UnaryOperator <String > function ,
108101 final UnaryOperator <ObjectNode > emptyObjectConverter ) {
109- if (src .isTextual ()) {
110- return new TextNode (function .apply (src .asText ()));
111- }
112-
113102 if (!src .isObject ()) {
114103 return src ;
115104 }
@@ -124,17 +113,6 @@ public static JsonNode recursiveClone(
124113 if (value .isObject ()) {
125114 newValue = recursiveClone (value , function , emptyObjectConverter );
126115 }
127- if (value .isArray ()) {
128- newValue = new ArrayNode (JsonNodeFactory .instance );
129- for (int i = 0 ; i < value .size (); i ++) {
130- final JsonNode elementValue =
131- recursiveClone (value .get (i ), function , emptyObjectConverter );
132- ((ArrayNode ) newValue ).add (elementValue );
133- }
134- }
135- if (newValue .isTextual ()) {
136- newValue = new TextNode (function .apply (newValue .asText ()));
137- }
138116 tgt .set (newFieldName , newValue );
139117 }
140118 return tgt .isEmpty () ? emptyObjectConverter .apply (tgt ) : tgt ;
0 commit comments