Skip to content

Commit efd8c42

Browse files
authored
Fix #4992: rename JsonNodeFactory.textNode() as stringNode() (#4993)
1 parent 6638956 commit efd8c42

13 files changed

+26
-19
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Versions: 3.x (for earlier see VERSION-2.x)
9898
`JsonNode.xxxStringYyy()` [JSTEP-3]
9999
#4891: Change 3.0 to use `module-info.java` directly for build (instead of via Moditect)
100100
#4956: Rename `JsonNode.isContainerNode()` as `isContainerNode()`
101+
#4992: Rename `JsonNodeFactory.textNode()` as `JsonNodeFactory.stringNode()` [JSTEP-3]
101102
- Remove `MappingJsonFactory`
102103
- Add context parameter for `TypeSerializer` contextualization (`forProperty()`)
103104
- Default for `JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES` changed to `false` for 3.0

src/main/java/tools/jackson/databind/ObjectMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ public JsonNode booleanNode(boolean b) {
859859

860860
@Override
861861
public JsonNode stringNode(String text) {
862-
return _deserializationConfig.getNodeFactory().textNode(text);
862+
return _deserializationConfig.getNodeFactory().stringNode(text);
863863
}
864864

865865
@Override

src/main/java/tools/jackson/databind/ObjectReader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ public JsonNode booleanNode(boolean b) {
993993

994994
@Override
995995
public JsonNode stringNode(String text) {
996-
return _config.getNodeFactory().textNode(text);
996+
return _config.getNodeFactory().stringNode(text);
997997
}
998998

999999
@Override

src/main/java/tools/jackson/databind/deser/jackson/BaseNodeDeserializer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ protected final JsonNode updateObject(JsonParser p, DeserializationContext ctxt,
262262
stack, nodeFactory.arrayNode());
263263
break;
264264
case JsonTokenId.ID_STRING:
265-
value = nodeFactory.textNode(p.getString());
265+
value = nodeFactory.stringNode(p.getString());
266266
break;
267267
case JsonTokenId.ID_NUMBER_INT:
268268
value = _fromInt(p, ctxt, nodeFactory);
@@ -345,7 +345,7 @@ protected final ContainerNode<?> _deserializeContainerNoRecursion(JsonParser p,
345345
}
346346
continue outer_loop;
347347
case JsonTokenId.ID_STRING:
348-
value = nodeFactory.textNode(p.getString());
348+
value = nodeFactory.stringNode(p.getString());
349349
break;
350350
case JsonTokenId.ID_NUMBER_INT:
351351
value = _fromInt(p, intCoercionFeats, nodeFactory);
@@ -400,7 +400,7 @@ protected final ContainerNode<?> _deserializeContainerNoRecursion(JsonParser p,
400400
case JsonTokenId.ID_END_ARRAY:
401401
break arrayLoop;
402402
case JsonTokenId.ID_STRING:
403-
currArray.add(nodeFactory.textNode(p.getString()));
403+
currArray.add(nodeFactory.stringNode(p.getString()));
404404
continue arrayLoop;
405405
case JsonTokenId.ID_NUMBER_INT:
406406
currArray.add(_fromInt(p, intCoercionFeats, nodeFactory));
@@ -440,7 +440,7 @@ protected final JsonNode _deserializeAnyScalar(JsonParser p, DeserializationCont
440440
case JsonTokenId.ID_END_OBJECT:
441441
return nodeF.objectNode();
442442
case JsonTokenId.ID_STRING:
443-
return nodeF.textNode(p.getString());
443+
return nodeF.stringNode(p.getString());
444444
case JsonTokenId.ID_NUMBER_INT:
445445
return _fromInt(p, ctxt, nodeF);
446446
case JsonTokenId.ID_NUMBER_FLOAT:

src/main/java/tools/jackson/databind/node/ArrayNode.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ public ArrayNode add(BigInteger v) {
712712
* @return This array node, to allow chaining
713713
*/
714714
public ArrayNode add(String v) {
715-
return _add((v == null) ? nullNode() : textNode(v));
715+
return _add((v == null) ? nullNode() : stringNode(v));
716716
}
717717

718718
/**
@@ -933,7 +933,7 @@ public ArrayNode insert(int index, BigInteger v) {
933933
* @return This array node, to allow chaining
934934
*/
935935
public ArrayNode insert(int index, String v) {
936-
return _insert(index, (v == null) ? nullNode() : textNode(v));
936+
return _insert(index, (v == null) ? nullNode() : stringNode(v));
937937
}
938938

939939
/**
@@ -1104,7 +1104,7 @@ public ArrayNode set(int index, BigInteger v) {
11041104
* @return This node (to allow chaining)
11051105
*/
11061106
public ArrayNode set(int index, String v) {
1107-
return _set(index, (v == null) ? nullNode() : textNode(v));
1107+
return _set(index, (v == null) ? nullNode() : stringNode(v));
11081108
}
11091109

11101110
/**

src/main/java/tools/jackson/databind/node/ContainerNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public final NumericNode numberNode(long v) {
151151
public final ValueNode numberNode(Double v) { return _nodeFactory.numberNode(v); }
152152

153153
@Override
154-
public final StringNode textNode(String text) { return _nodeFactory.textNode(text); }
154+
public final StringNode stringNode(String text) { return _nodeFactory.stringNode(text); }
155155

156156
@Override
157157
public final BinaryNode binaryNode(byte[] data) { return _nodeFactory.binaryNode(data); }

src/main/java/tools/jackson/databind/node/JsonNodeCreator.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ public interface JsonNodeCreator
4545

4646
// Textual nodes
4747

48-
public ValueNode textNode(String text);
48+
public ValueNode stringNode(String text);
49+
50+
/**
51+
* @deprecated since 3.0 Use {@link #stringNode(String)} instead
52+
*/
53+
@Deprecated // since 3.0
54+
public default ValueNode textNode(String text) { return stringNode(text); }
4955

5056
// Other value (non-structured) nodes
5157

src/main/java/tools/jackson/databind/node/JsonNodeFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public ValueNode numberNode(BigDecimal v)
241241
* String value
242242
*/
243243
@Override
244-
public StringNode textNode(String text) { return StringNode.valueOf(text); }
244+
public StringNode stringNode(String text) { return StringNode.valueOf(text); }
245245

246246
/**
247247
* Factory method for constructing a node that represents given

src/main/java/tools/jackson/databind/node/ObjectNode.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ public ObjectNode put(String propertyName, BigInteger v) {
966966
*/
967967
public ObjectNode put(String propertyName, String v) {
968968
return _put(propertyName, (v == null) ? nullNode()
969-
: textNode(v));
969+
: stringNode(v));
970970
}
971971

972972
/**

src/main/java/tools/jackson/databind/node/TreeBuildingGenerator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ public TreeWriteContext createChildObjectContext(Object currValue)
615615
@Override
616616
public void writeNumber(ValueNode v) { _node = v; }
617617
@Override
618-
public void writeString(String v) { _node = _nodeFactory.textNode(v); }
618+
public void writeString(String v) { _node = _nodeFactory.stringNode(v); }
619619

620620
@Override
621621
public void writePOJO(Object value) { _node = _nodeFactory.pojoNode(value); }

src/test/java/tools/jackson/databind/node/ArrayNodeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void testDirectCreation2() throws Exception
117117
JsonNodeFactory f = MAPPER.getNodeFactory();
118118
ArrayList<JsonNode> list = new ArrayList<>();
119119
list.add(f.booleanNode(true));
120-
list.add(f.textNode("foo"));
120+
list.add(f.stringNode("foo"));
121121
ArrayNode n = new ArrayNode(f, list);
122122
assertEquals(2, n.size());
123123
assertTrue(n.get(0).isBoolean());

src/test/java/tools/jackson/databind/node/NodeJDKSerializationTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void testScalarSerialization() throws Exception
8484
{
8585
testNodeRoundtrip(MAPPER.getNodeFactory().nullNode());
8686

87-
testNodeRoundtrip(MAPPER.getNodeFactory().textNode("Foobar"));
87+
testNodeRoundtrip(MAPPER.getNodeFactory().stringNode("Foobar"));
8888

8989
testNodeRoundtrip(MAPPER.getNodeFactory().booleanNode(true));
9090
testNodeRoundtrip(MAPPER.getNodeFactory().booleanNode(false));

src/test/java/tools/jackson/databind/node/ObjectNodeTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public void testBasicsPutSet()
202202
final JsonNodeFactory f = JsonNodeFactory.instance;
203203
ObjectNode root = f.objectNode();
204204
JsonNode old;
205-
old = root.putIfAbsent("key", f.textNode("foobar"));
205+
old = root.putIfAbsent("key", f.stringNode("foobar"));
206206
assertNull(old);
207207
assertEquals(1, root.size());
208208
old = root.putIfAbsent("key", f.numberNode(3));
@@ -528,7 +528,7 @@ public void testPropertiesTraversal() throws Exception
528528
{
529529
// Nothing to traverse for other types
530530
assertEquals("", _toString(MAPPER.createArrayNode()));
531-
assertEquals("", _toString(MAPPER.getNodeFactory().textNode("foo")));
531+
assertEquals("", _toString(MAPPER.getNodeFactory().stringNode("foo")));
532532

533533
// But yes for ObjectNode:
534534
JsonNode n = MAPPER.readTree(a2q(
@@ -543,7 +543,7 @@ public void testStreamMethods()
543543
ObjectMapper mapper = objectMapper();
544544
ObjectNode obj = mapper.createObjectNode();
545545
JsonNode n1 = obj.numberNode(42);
546-
JsonNode n2 = obj.textNode("foo");
546+
JsonNode n2 = obj.stringNode("foo");
547547

548548
obj.set("a", n1);
549549
obj.set("b", n2);

0 commit comments

Comments
 (0)