@@ -1119,22 +1119,33 @@ public final List<JsonNode> findParents(String fieldName)
1119
1119
*/
1120
1120
1121
1121
/**
1122
- * Method that can be called on Object nodes, to access a property
1123
- * that has Object value; or if no such property exists, to create,
1124
- * add and return such Object node.
1125
- * If the node method is called on is not Object node,
1126
- * or if property exists and has value that is not Object node,
1127
- * {@link UnsupportedOperationException} is thrown
1122
+ * Short-cut equivalent to:
1123
+ *<pre>
1124
+ * withObject(JsonPointer.compile(expr);
1125
+ *</pre>
1126
+ * see {@link #withObject(JsonPointer)} for full explanation.
1128
1127
*
1129
- * @param propertyName Name of property for the {@link ObjectNode}
1128
+ * @param expr {@link JsonPointer} expression to use
1130
1129
*
1131
1130
* @return {@link ObjectNode} found or created
1132
1131
*
1133
1132
* @since 2.14
1134
1133
*/
1135
- public ObjectNode withObject (String propertyName ) {
1136
- throw new UnsupportedOperationException ("`JsonNode` not of type `ObjectNode` (but "
1137
- +getClass ().getName ()+"), cannot call `withObject()` on it" );
1134
+ public final ObjectNode withObject (String expr ) {
1135
+ return withObject (JsonPointer .compile (expr ));
1136
+ }
1137
+
1138
+ /**
1139
+ * Short-cut equivalent to:
1140
+ *<pre>
1141
+ * withObject(JsonPointer.compile(expr), overwriteMode, preferIndex);
1142
+ *</pre>
1143
+ *
1144
+ * @since 2.14
1145
+ */
1146
+ public final ObjectNode withObject (String expr ,
1147
+ OverwriteMode overwriteMode , boolean preferIndex ) {
1148
+ return withObject (JsonPointer .compile (expr ), overwriteMode , preferIndex );
1138
1149
}
1139
1150
1140
1151
/**
@@ -1231,31 +1242,68 @@ public ObjectNode withObject(JsonPointer ptr,
1231
1242
}
1232
1243
1233
1244
/**
1245
+ * Method that works in one of possible ways, depending on whether
1246
+ * {@code exprOrProperty} is a valid {@link JsonPointer} expression or
1247
+ * not (valid expression is either empty String {@code ""} or starts
1248
+ * with leading slash {@code /} character).
1249
+ * If it is, works as a short-cut to:
1250
+ *<pre>
1251
+ * withObject(JsonPointer.compile(exprOrProperty));
1252
+ *</pre>
1253
+ * If it is NOT a valid {@link JsonPointer} expression, value is taken
1254
+ * as a literal Object property name and traversed like a single-segment
1255
+ * {@link JsonPointer}.
1256
+ *<p>
1257
+ * NOTE: before Jackson 2.14 behavior was always that of non-expression usage;
1258
+ * that is, {@code exprOrProperty} was always considered as a simple property name.
1259
+ *
1234
1260
* @deprecated Since 2.14 use {@code withObject(String)} instead
1235
1261
*/
1236
- @ SuppressWarnings ("unchecked" )
1237
1262
@ Deprecated // since 2.14
1238
- public final <T extends JsonNode > T with (String propertyName ) {
1239
- return (T ) withObject (propertyName );
1263
+ public <T extends JsonNode > T with (String exprOrProperty ) {
1264
+ throw new UnsupportedOperationException ("`JsonNode` not of type `ObjectNode` (but "
1265
+ +getClass ().getName ()+"), cannot call `with(String)` on it" );
1240
1266
}
1241
1267
1242
1268
/**
1243
- * Method that can be called on {@link ObjectNode} nodes, to access a property
1244
- * that has <code>Array</code> value; or if no such property exists, to create,
1245
- * add and return such Array node.
1246
- * If the node method is called on is not Object node,
1247
- * or if property exists and has value that is not Array node,
1248
- * {@link UnsupportedOperationException} is thrown
1269
+ * Method that works in one of possible ways, depending on whether
1270
+ * {@code exprOrProperty} is a valid {@link JsonPointer} expression or
1271
+ * not (valid expression is either empty String {@code ""} or starts
1272
+ * with leading slash {@code /} character).
1273
+ * If it is, works as a short-cut to:
1274
+ *<pre>
1275
+ * withObject(JsonPointer.compile(exprOrProperty));
1276
+ *</pre>
1277
+ * If it is NOT a valid {@link JsonPointer} expression, value is taken
1278
+ * as a literal Object property name and traversed like a single-segment
1279
+ * {@link JsonPointer}.
1280
+ *<p>
1281
+ * NOTE: before Jackson 2.14 behavior was always that of non-expression usage;
1282
+ * that is, {@code exprOrProperty} was always considered as a simple property name.
1249
1283
*
1250
- * @param propertyName Name of property for the {@link ArrayNode}
1284
+ * @param exprOrProperty Either {@link JsonPointer} expression for full access (if valid
1285
+ * pointer expression), or the name of property for the {@link ArrayNode}.
1251
1286
*
1252
1287
* @return {@link ArrayNode} found or created
1253
1288
*/
1254
- public <T extends JsonNode > T withArray (String propertyName ) {
1289
+ public <T extends JsonNode > T withArray (String exprOrProperty ) {
1255
1290
throw new UnsupportedOperationException ("`JsonNode` not of type `ObjectNode` (but `"
1256
1291
+getClass ().getName ()+")`, cannot call `withArray()` on it" );
1257
1292
}
1258
1293
1294
+ /**
1295
+ * Short-cut equivalent to:
1296
+ *<pre>
1297
+ * withArray(JsonPointer.compile(expr), overwriteMode, preferIndex);
1298
+ *</pre>
1299
+ *
1300
+ * @since 2.14
1301
+ */
1302
+ public ArrayNode withArray (String expr ,
1303
+ OverwriteMode overwriteMode , boolean preferIndex ) {
1304
+ return withArray (JsonPointer .compile (expr ), overwriteMode , preferIndex );
1305
+ }
1306
+
1259
1307
/**
1260
1308
* Same as {@link #withArray(JsonPointer, OverwriteMode, boolean)} but
1261
1309
* with defaults of {@code OvewriteMode#NULLS} (overwrite mode)
0 commit comments