Skip to content

Commit 38b1f77

Browse files
authored
Fix #4879 (#4880)
1 parent 1ba52b8 commit 38b1f77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+306
-281
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ Versions: 3.x (for earlier see VERSION-2.x)
8787
#4865: Add spliterator support in `JsonNode`
8888
(contributed by @pjfanning)
8989
#4875: Remove `JsonNode.fields()` from 3.0
90+
#4879: Rename `TextNode` as `StringNode`; `JsonNode.xxxTextYyy()` (mostly) as
91+
`JsonNode.xxxStringYyy()` [JSTEP-3]
9092
- Remove `MappingJsonFactory`
9193
- Add context parameter for `TypeSerializer` contextualization (`forProperty()`)
9294
- Default for `JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES` changed to `false` for 3.0

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

+71-45
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public boolean isObject() {
200200
* field. Null otherwise.
201201
*/
202202
@Override
203-
public JsonNode get(String fieldName) { return null; }
203+
public JsonNode get(String propertyName) { return null; }
204204

205205
/**
206206
* Method for accessing value of the specified element of
@@ -259,7 +259,7 @@ public boolean isObject() {
259259
*/
260260

261261
@Override
262-
public abstract JsonNode path(String fieldName);
262+
public abstract JsonNode path(String propertyName);
263263

264264
/**
265265
* This method is similar to {@link #get(int)}, except
@@ -424,13 +424,21 @@ public final boolean isNumber() {
424424
public boolean isBigInteger() { return false; }
425425

426426
/**
427-
* Method that checks whether this node represents basic JSON String
427+
* Method that checks whether this node represents JSON String
428428
* value.
429429
*/
430-
public final boolean isTextual() {
430+
public final boolean isString() {
431431
return getNodeType() == JsonNodeType.STRING;
432432
}
433433

434+
/**
435+
* @deprecated Use {@link #isString} instead.
436+
*/
437+
@Deprecated // since 3.0
438+
public boolean isTextual() {
439+
return isString();
440+
}
441+
434442
/**
435443
* Method that can be used to check if this node was created from
436444
* JSON boolean value (literals "true" and "false").
@@ -451,7 +459,7 @@ public final boolean isNull() {
451459
/**
452460
* Method that can be used to check if this node represents
453461
* binary data (Base64 encoded). Although this will be externally
454-
* written as JSON String value, {@link #isTextual} will
462+
* written as JSON String value, {@link #isString} will
455463
* return false if this method returns true.
456464
*
457465
* @return True if this node represents base64 encoded binary data
@@ -522,19 +530,21 @@ public boolean canConvertToExactIntegral() {
522530
/**
523531
* Method to use for accessing String values.
524532
* Does <b>NOT</b> do any conversions for non-String value nodes;
525-
* for non-String values (ones for which {@link #isTextual} returns
533+
* for non-String values (ones for which {@link #isString} returns
526534
* false) null will be returned.
527535
* For String values, null is never returned (but empty Strings may be)
536+
*<p>
537+
* NOTE: in Jackson 2.x, was {@code textValue()}.
528538
*
529-
* @return Textual value this node contains, iff it is a textual
530-
* JSON node (comes from JSON String value entry)
539+
* @return String value this node contains, iff node is created from
540+
* a String value.
531541
*/
532-
public String textValue() { return null; }
542+
public String stringValue() { return null; }
533543

534544
/**
535545
* Method to use for accessing binary content of binary nodes (nodes
536-
* for which {@link #isBinary} returns true); or for Text Nodes
537-
* (ones for which {@link #textValue} returns non-null value),
546+
* for which {@link #isBinary} returns true); or for String Nodes
547+
* (ones for which {@link #stringValue} returns non-null value),
538548
* to read decoded base64 data.
539549
* For other types of nodes, returns null.
540550
*
@@ -652,11 +662,15 @@ public byte[] binaryValue() {
652662

653663
/**
654664
* Method that will return a valid String representation of
655-
* the container value, if the node is a value node
665+
* the contained value, if the node is a value node
656666
* (method {@link #isValueNode} returns true),
657667
* otherwise empty String.
668+
*<p>
669+
* NOTE: this is NOT same as {@link #toString()} in that result is
670+
* <p>NOT VALID ENCODED JSON</p> for all nodes (but is for some, like
671+
* {@code NumberNode}s and {@code BooleanNode}s).
658672
*/
659-
public abstract String asText();
673+
public abstract String asString();
660674

661675
/**
662676
* Returns the text value of this node or the provided {@code defaultValue} if this node
@@ -666,11 +680,27 @@ public byte[] binaryValue() {
666680
* @param defaultValue The default value to return if this node's text value is absent.
667681
* @return The text value of this node, or {@code defaultValue} if the text value is absent.
668682
*/
669-
public String asText(String defaultValue) {
670-
String str = asText();
683+
public String asString(String defaultValue) {
684+
String str = asString();
671685
return (str == null) ? defaultValue : str;
672686
}
673687

688+
/**
689+
* @deprecated Use {@link #asString()} instead.
690+
*/
691+
@Deprecated // since 3.0
692+
public final String asText() {
693+
return asString();
694+
}
695+
696+
/**
697+
* @deprecated Use {@link #asString(String)} instead.
698+
*/
699+
@Deprecated // since 3.0
700+
public String asText(String defaultValue) {
701+
return asString(defaultValue);
702+
}
703+
674704
/**
675705
* Method that will try to convert value of this node to a Java <b>int</b>.
676706
* Numbers are coerced using default Java rules; booleans convert to 0 (false)
@@ -832,10 +862,10 @@ public <T extends JsonNode> T requireNonNull() {
832862
/**
833863
* Method is functionally equivalent to
834864
*{@code
835-
* path(fieldName).required()
865+
* path(propertyName).required()
836866
*}
837867
* and can be used to check that this node is an {@code ObjectNode} (that is, represents
838-
* JSON Object value) and has value for specified property with key {@code fieldName}
868+
* JSON Object value) and has value for specified property with key {@code propertyName}
839869
* (but note that value may be explicit JSON null value).
840870
* If this node is Object Node and has value for specified property, matching value
841871
* is returned; otherwise {@link IllegalArgumentException} is thrown.
@@ -943,20 +973,20 @@ public final JsonNode requiredAt(final JsonPointer path) {
943973
*<p>
944974
* This method is equivalent to:
945975
*<pre>
946-
* node.get(fieldName) != null
976+
* node.get(propertyName) != null
947977
*</pre>
948978
* (since return value of get() is node, not value node contains)
949979
*<p>
950980
* NOTE: when explicit <code>null</code> values are added, this
951981
* method will return <code>true</code> for such properties.
952982
*
953-
* @param fieldName Name of element to check
983+
* @param propertyName Name of element to check
954984
*
955985
* @return True if this node is a JSON Object node, and has a property
956986
* entry with specified name (with any value, including null value)
957987
*/
958-
public boolean has(String fieldName) {
959-
return get(fieldName) != null;
988+
public boolean has(String propertyName) {
989+
return get(propertyName) != null;
960990
}
961991

962992
/**
@@ -991,13 +1021,11 @@ public boolean has(int index) {
9911021
*<p>
9921022
* This method is functionally equivalent to:
9931023
*<pre>
994-
* node.get(fieldName) != null &amp;&amp; !node.get(fieldName).isNull()
1024+
* node.get(propertyName) != null &amp;&amp; !node.get(propertyName).isNull()
9951025
*</pre>
996-
*
997-
* @since 2.1
9981026
*/
999-
public boolean hasNonNull(String fieldName) {
1000-
JsonNode n = get(fieldName);
1027+
public boolean hasNonNull(String propertyName) {
1028+
JsonNode n = get(propertyName);
10011029
return (n != null) && !n.isNull();
10021030
}
10031031

@@ -1009,8 +1037,6 @@ public boolean hasNonNull(String fieldName) {
10091037
*<pre>
10101038
* node.get(index) != null &amp;&amp; !node.get(index).isNull()
10111039
*</pre>
1012-
*
1013-
* @since 2.1
10141040
*/
10151041
public boolean hasNonNull(int index) {
10161042
JsonNode n = get(index);
@@ -1135,11 +1161,11 @@ public void forEachEntry(BiConsumer<? super String, ? super JsonNode> action) {
11351161
* Note that traversal is done in document order (that is, order in which
11361162
* nodes are iterated if using {@link JsonNode#values()})
11371163
*
1138-
* @param fieldName Name of field to look for
1164+
* @param propertyName Name of field to look for
11391165
*
11401166
* @return Value of first matching node found, if any; null if none
11411167
*/
1142-
public abstract JsonNode findValue(String fieldName);
1168+
public abstract JsonNode findValue(String propertyName);
11431169

11441170
/**
11451171
* Method for finding JSON Object fields with specified name -- both immediate
@@ -1150,11 +1176,11 @@ public void forEachEntry(BiConsumer<? super String, ? super JsonNode> action) {
11501176
* If no matching fields are found in this node or its descendants, returns
11511177
* an empty List.
11521178
*
1153-
* @param fieldName Name of field to look for
1179+
* @param propertyName Name of field to look for
11541180
*/
1155-
public final List<JsonNode> findValues(String fieldName)
1181+
public final List<JsonNode> findValues(String propertyName)
11561182
{
1157-
List<JsonNode> result = findValues(fieldName, null);
1183+
List<JsonNode> result = findValues(propertyName, null);
11581184
if (result == null) {
11591185
return Collections.emptyList();
11601186
}
@@ -1165,9 +1191,9 @@ public final List<JsonNode> findValues(String fieldName)
11651191
* Similar to {@link #findValues}, but will additionally convert
11661192
* values into Strings, calling {@link #asText}.
11671193
*/
1168-
public final List<String> findValuesAsText(String fieldName)
1194+
public final List<String> findValuesAsString(String propertyName)
11691195
{
1170-
List<String> result = findValuesAsText(fieldName, null);
1196+
List<String> result = findValuesAsString(propertyName, null);
11711197
if (result == null) {
11721198
return Collections.emptyList();
11731199
}
@@ -1181,45 +1207,45 @@ public final List<String> findValuesAsText(String fieldName)
11811207
* returns true; and all value access methods return empty or
11821208
* missing value.
11831209
*
1184-
* @param fieldName Name of field to look for
1210+
* @param propertyName Name of field to look for
11851211
*
11861212
* @return Value of first matching node found; or if not found, a
11871213
* "missing node" (non-null instance that has no value)
11881214
*/
1189-
public abstract JsonNode findPath(String fieldName);
1215+
public abstract JsonNode findPath(String propertyName);
11901216

11911217
/**
11921218
* Method for finding a JSON Object that contains specified field,
11931219
* within this node or its descendants.
11941220
* If no matching field is found in this node or its descendants, returns null.
11951221
*
1196-
* @param fieldName Name of field to look for
1222+
* @param propertyName Name of field to look for
11971223
*
11981224
* @return Value of first matching node found, if any; null if none
11991225
*/
1200-
public abstract JsonNode findParent(String fieldName);
1226+
public abstract JsonNode findParent(String propertyName);
12011227

12021228
/**
12031229
* Method for finding a JSON Object that contains specified field,
12041230
* within this node or its descendants.
12051231
* If no matching field is found in this node or its descendants, returns null.
12061232
*
1207-
* @param fieldName Name of field to look for
1233+
* @param propertyName Name of field to look for
12081234
*
12091235
* @return Value of first matching node found, if any; null if none
12101236
*/
1211-
public final List<JsonNode> findParents(String fieldName)
1237+
public final List<JsonNode> findParents(String propertyName)
12121238
{
1213-
List<JsonNode> result = findParents(fieldName, null);
1239+
List<JsonNode> result = findParents(propertyName, null);
12141240
if (result == null) {
12151241
return Collections.emptyList();
12161242
}
12171243
return result;
12181244
}
12191245

1220-
public abstract List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar);
1221-
public abstract List<String> findValuesAsText(String fieldName, List<String> foundSoFar);
1222-
public abstract List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar);
1246+
public abstract List<JsonNode> findValues(String propertyName, List<JsonNode> foundSoFar);
1247+
public abstract List<String> findValuesAsString(String propertyName, List<String> foundSoFar);
1248+
public abstract List<JsonNode> findParents(String propertyName, List<JsonNode> foundSoFar);
12231249

12241250
/*
12251251
/**********************************************************************

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ public List<JsonNode> findValues(String propertyName, List<JsonNode> foundSoFar)
361361
}
362362

363363
@Override
364-
public List<String> findValuesAsText(String propertyName, List<String> foundSoFar)
364+
public List<String> findValuesAsString(String propertyName, List<String> foundSoFar)
365365
{
366366
for (JsonNode node : _children) {
367-
foundSoFar = node.findValuesAsText(propertyName, foundSoFar);
367+
foundSoFar = node.findValuesAsString(propertyName, foundSoFar);
368368
}
369369
return foundSoFar;
370370
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public Number numberValue() {
9393
*/
9494

9595
@Override
96-
public String asText() {
96+
public String asString() {
9797
return _value.toString();
9898
}
9999

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public JsonToken asToken() {
8484
* but will work correctly.
8585
*/
8686
@Override
87-
public String asText() {
87+
public String asString() {
8888
return Base64Variants.getDefaultVariant().encode(_data, false);
8989
}
9090

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public boolean booleanValue() {
6262
}
6363

6464
@Override
65-
public String asText() {
65+
public String asString() {
6666
return _value ? "true" : "false";
6767
}
6868

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected ContainerNode(JsonNodeFactory nc) {
3838
public abstract JsonToken asToken();
3939

4040
@Override
41-
public String asText() { return ""; }
41+
public String asString() { return ""; }
4242

4343
/*
4444
/**********************************************************************
@@ -145,7 +145,7 @@ public final NumericNode numberNode(long v) {
145145
public final ValueNode numberNode(Double v) { return _nodeFactory.numberNode(v); }
146146

147147
@Override
148-
public final TextNode textNode(String text) { return _nodeFactory.textNode(text); }
148+
public final StringNode textNode(String text) { return _nodeFactory.textNode(text); }
149149

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public BigInteger bigIntegerValue() {
103103
public BigDecimal decimalValue() { return _value; }
104104

105105
@Override
106-
public String asText() {
106+
public String asString() {
107107
return _value.toString();
108108
}
109109

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public BigInteger bigIntegerValue() {
9393
}
9494

9595
@Override
96-
public String asText() {
96+
public String asString() {
9797
return String.valueOf(_value);
9898
}
9999

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public BigInteger bigIntegerValue() {
9393
}
9494

9595
@Override
96-
public String asText() {
96+
public String asString() {
9797
return String.valueOf(_value);
9898
}
9999

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public Number numberValue() {
100100
public BigInteger bigIntegerValue() { return BigInteger.valueOf(_value); }
101101

102102
@Override
103-
public String asText() {
103+
public String asString() {
104104
return String.valueOf(_value);
105105
}
106106

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 TextNode textNode(String text) { return TextNode.valueOf(text); }
244+
public StringNode textNode(String text) { return StringNode.valueOf(text); }
245245

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

0 commit comments

Comments
 (0)