Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix #4416: Deprecate JsonNode.asText(String) #4419

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1752,3 +1752,7 @@ Jesper Blomquist (jebl01@github)
* Contributed #4393: Deserialize `java.util.UUID` encoded as Base64 and base64Url with or
without padding
(2.17.0)

András Péteri (apeteri@github)
* Suggested #4416: Deprecate `JsonNode.asText(String)`
(2.17.0)
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Project: jackson-databind
#4394: Better Base64 support for `java.util.UUIDs`
without padding
(fix contributed by Jesper B)
#4416: Deprecate `JsonNode.asText(String)`
(suggested by András P)
- JUnit5 upgraded to 5.10.1

2.16.2 (not yet released)
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/fasterxml/jackson/databind/JsonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,16 @@ public byte[] binaryValue() throws IOException {
* <code>defaultValue</code> in cases where null value would be returned;
* either for missing nodes (trying to access missing property, or element
* at invalid item for array) or explicit nulls.
*<p>
* NOTE: deprecated since 2.17 because {@link #asText()} very rarely returns
* {@code null} for any node types -- in fact, neither {@link MissingNode}
* nor {@code NullNode} return {@code null} from {@link #asText()}.
*
* @since 2.4
*
* @deprecated Since 2.17, to be removed from 3.0
*/
@Deprecated // @since 2.17
public String asText(String defaultValue) {
String str = asText();
return (str == null) ? defaultValue : str;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public NamedPoint deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonNode tree = ctxt.readTree(p);
String name = tree.path("name").asText(null);
String name = tree.path("name").asText();
Point point = ctxt.readTreeAsValue(tree.get("point"), Point.class);
return new NamedPoint(name, point);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testInt()
assertEquals(BigInteger.ONE, n.bigIntegerValue());
assertEquals("1", n.asText());
// 2.4
assertEquals("1", n.asText("foo"));
assertEquals("1", n.asText());

assertNodeNumbers(n, 1, 1.0);

Expand Down