Skip to content

Commit 0c02ed5

Browse files
committed
Fix #1058
1 parent 027ea1b commit 0c02ed5

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Versions: 3.x (for earlier see VERSION-2.x)
77

88
3.0.0 (not yet released)
99

10+
#1058: Add a way to pass std and format-specific parser/generator flags during
11+
parser/generation construction
1012
#1762: `StdDateFormat`: serialize time offset using colon
1113
#1772: Remove `MapperFeature. USE_STD_BEAN_NAMING`
1214
#1773: Remove `MapperFeature.AUTO_DETECT_xxx` features

src/main/java/com/fasterxml/jackson/databind/node/ArrayNode.java

+32-11
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,52 @@ public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar)
232232
*/
233233

234234
/**
235-
* Method that will set specified field, replacing old value,
236-
* if any.
235+
* Method that will set specified element, replacing old value.
237236
*
238-
* @param value to set field to; if null, will be converted
237+
* @param value to set element to; if null, will be converted
239238
* to a {@link NullNode} first (to remove field entry, call
240239
* {@link #remove} instead)
241240
*
242-
* @return Old value of the field, if any; null if there was no
243-
* old value.
241+
* @return This node after adding/replacing property value (to allow chaining)
242+
*
243+
* @throws IndexOutOfBoundsException If Array does not have specified element
244+
* (that is, index is outside valid range of elements in array)
244245
*/
245-
public JsonNode set(int index, JsonNode value)
246+
public ArrayNode set(int index, JsonNode value)
246247
{
247248
if (value == null) { // let's not store 'raw' nulls but nodes
248249
value = nullNode();
249250
}
250251
if (index < 0 || index >= _children.size()) {
251252
throw new IndexOutOfBoundsException("Illegal index "+ index +", array size "+size());
252253
}
253-
return _children.set(index, value);
254+
_children.set(index, value);
255+
return this;
254256
}
255257

258+
/**
259+
* Method that will set specified element, replacing old value.
260+
*
261+
* @param value to set element to; if null, will be converted
262+
* to a {@link NullNode} first (to remove field entry, call
263+
* {@link #remove} instead)
264+
*
265+
* @return Old value of the element, if any; null if no such element existed.
266+
*
267+
* @throws IndexOutOfBoundsException If Array does not have specified element
268+
* (that is, index is outside valid range of elements in array)
269+
*/
270+
public JsonNode replace(int index, JsonNode value)
271+
{
272+
if (value == null) { // let's not store 'raw' nulls but nodes
273+
value = nullNode();
274+
}
275+
if (index < 0 || index >= _children.size()) {
276+
throw new IndexOutOfBoundsException("Illegal index "+ index +", array size "+size());
277+
}
278+
return _children.set(index, value);
279+
}
280+
256281
/**
257282
* Method for adding specified node at the end of this array.
258283
*
@@ -390,8 +415,6 @@ public ArrayNode addPOJO(Object value)
390415

391416
/**
392417
* @return This array node, to allow chaining
393-
*
394-
* @since 2.6
395418
*/
396419
public ArrayNode addRawValue(RawValue raw) {
397420
if (raw == null) {
@@ -516,8 +539,6 @@ public ArrayNode add(BigDecimal v) {
516539
* Method for adding specified number at the end of this array.
517540
*
518541
* @return This array node, to allow chaining
519-
*
520-
* @since 2.9
521542
*/
522543
public ArrayNode add(BigInteger v) {
523544
if (v == null) {

src/main/java/com/fasterxml/jackson/databind/node/ObjectNode.java

+5-22
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public void serializeWithType(JsonGenerator g, SerializerProvider provider,
334334

335335
/*
336336
/**********************************************************
337-
/* Extended ObjectNode API, mutators, since 2.1
337+
/* Extended ObjectNode API, mutators
338338
/**********************************************************
339339
*/
340340

@@ -348,10 +348,8 @@ public void serializeWithType(JsonGenerator g, SerializerProvider provider,
348348
* {@link #remove} instead)
349349
*
350350
* @return This node after adding/replacing property value (to allow chaining)
351-
*
352-
* @since 2.1
353351
*/
354-
public JsonNode set(String fieldName, JsonNode value)
352+
public ObjectNode set(String fieldName, JsonNode value)
355353
{
356354
if (value == null) {
357355
value = nullNode();
@@ -367,10 +365,8 @@ public JsonNode set(String fieldName, JsonNode value)
367365
* @param properties Properties to add
368366
*
369367
* @return This node after adding/replacing property values (to allow chaining)
370-
*
371-
* @since 2.1
372368
*/
373-
public JsonNode setAll(Map<String,? extends JsonNode> properties)
369+
public ObjectNode setAll(Map<String,? extends JsonNode> properties)
374370
{
375371
for (Map.Entry<String,? extends JsonNode> en : properties.entrySet()) {
376372
JsonNode n = en.getValue();
@@ -389,10 +385,8 @@ public JsonNode setAll(Map<String,? extends JsonNode> properties)
389385
* @param other Object of which properties to add to this object
390386
*
391387
* @return This node after addition (to allow chaining)
392-
*
393-
* @since 2.1
394388
*/
395-
public JsonNode setAll(ObjectNode other)
389+
public ObjectNode setAll(ObjectNode other)
396390
{
397391
_children.putAll(other._children);
398392
return this;
@@ -407,8 +401,6 @@ public JsonNode setAll(ObjectNode other)
407401
*
408402
* @return Old value of the property; null if there was no such property
409403
* with value
410-
*
411-
* @since 2.1
412404
*/
413405
public JsonNode replace(String fieldName, JsonNode value)
414406
{
@@ -423,10 +415,8 @@ public JsonNode replace(String fieldName, JsonNode value)
423415
* returning instance after removal.
424416
*
425417
* @return This node after removing entry (if any)
426-
*
427-
* @since 2.1
428418
*/
429-
public JsonNode without(String fieldName)
419+
public ObjectNode without(String fieldName)
430420
{
431421
_children.remove(fieldName);
432422
return this;
@@ -439,8 +429,6 @@ public JsonNode without(String fieldName)
439429
* @param fieldNames Names of fields to remove
440430
*
441431
* @return This node after removing entries
442-
*
443-
* @since 2.1
444432
*/
445433
public ObjectNode without(Collection<String> fieldNames)
446434
{
@@ -567,9 +555,6 @@ public ObjectNode putPOJO(String fieldName, Object pojo) {
567555
return _put(fieldName, pojoNode(pojo));
568556
}
569557

570-
/**
571-
* @since 2.6
572-
*/
573558
public ObjectNode putRawValue(String fieldName, RawValue raw) {
574559
return _put(fieldName, rawValueNode(raw));
575560
}
@@ -711,8 +696,6 @@ public ObjectNode put(String fieldName, BigDecimal v) {
711696
* Method for setting value of a field to specified numeric value.
712697
*
713698
* @return This node (to allow chaining)
714-
*
715-
* @since 2.9
716699
*/
717700
public ObjectNode put(String fieldName, BigInteger v) {
718701
return _put(fieldName, (v == null) ? nullNode()

src/test/java/com/fasterxml/jackson/databind/MapperViaParserTest.java src/test/java/com/fasterxml/jackson/failing/MapperViaParserTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
package com.fasterxml.jackson.databind;
1+
package com.fasterxml.jackson.failing;
22

33
import java.io.IOException;
44
import java.io.StringReader;
55

66
import com.fasterxml.jackson.core.*;
77
import com.fasterxml.jackson.core.io.CharacterEscapes;
88
import com.fasterxml.jackson.core.io.SerializedString;
9+
import com.fasterxml.jackson.databind.BaseMapTest;
910
import com.fasterxml.jackson.databind.ObjectMapper;
1011

1112
public class MapperViaParserTest extends BaseMapTest

0 commit comments

Comments
 (0)