Skip to content

Commit 21220ee

Browse files
committed
Javadoc improvements wrt #2211
1 parent f0abe41 commit 21220ee

File tree

2 files changed

+47
-114
lines changed

2 files changed

+47
-114
lines changed

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

+20-98
Original file line numberDiff line numberDiff line change
@@ -2367,11 +2367,14 @@ public <T> T readValue(JsonParser p, JavaType valueType)
23672367
}
23682368

23692369
/**
2370-
* Method to deserialize JSON content as tree expressed
2371-
* using set of {@link JsonNode} instances. Returns
2372-
* root of the resulting tree (where root can consist
2373-
* of just a single node if the current event is a
2374-
* value event, not container).
2370+
* Method to deserialize JSON content as a tree {@link JsonNode}.
2371+
* Returns {@link JsonNode} that represents the root of the resulting tree, if there
2372+
* was content to read, or {@code null} if no more content is accessible
2373+
* via passed {@link JsonParser}.
2374+
*<p>
2375+
* NOTE! Behavior with end-of-input (no more content) differs between this
2376+
* {@code readTree} method, and all other methods that take input source: latter
2377+
* will return "missing node", NOT {@code null}
23752378
*
23762379
* @return a {@link JsonNode}, if valid JSON content found; null
23772380
* if input has no content to bind -- note, however, that if
@@ -2523,105 +2526,40 @@ public JsonNode readTree(InputStream in) throws IOException
25232526
}
25242527

25252528
/**
2526-
* Method to deserialize JSON content as tree expressed
2527-
* using set of {@link JsonNode} instances.
2528-
* Returns root of the resulting tree (where root can consist
2529-
* of just a single node if the current event is a
2530-
* value event, not container).
2531-
*<p>
2532-
* If a low-level I/O problem (missing input, network error) occurs,
2533-
* a {@link IOException} will be thrown.
2534-
* If a parsing problem occurs (invalid JSON),
2535-
* {@link JsonParseException} will be thrown.
2536-
* If no content is found from input (end-of-input), Java
2537-
* <code>null</code> will be returned.
2538-
*
2539-
* @param r Reader used to read JSON content
2540-
* for building the JSON tree.
2541-
*
2542-
* @return a {@link JsonNode}, if valid JSON content found; null
2543-
* if input has no content to bind -- note, however, that if
2544-
* JSON <code>null</code> token is found, it will be represented
2545-
* as a non-null {@link JsonNode} (one that returns <code>true</code>
2546-
* for {@link JsonNode#isNull()}
2529+
* Same as {@link #readTree(InputStream)} except content accessed through
2530+
* passed-in {@link Reader}
25472531
*/
25482532
public JsonNode readTree(Reader r) throws IOException {
25492533
return _readTreeAndClose(_jsonFactory.createParser(r));
25502534
}
25512535

25522536
/**
2553-
* Method to deserialize JSON content as tree expressed using set of {@link JsonNode} instances.
2554-
* Returns root of the resulting tree (where root can consist of just a single node if the current
2555-
* event is a value event, not container).
2556-
*<p>
2557-
* If a low-level I/O problem (missing input, network error) occurs,
2558-
* a {@link IOException} will be thrown.
2559-
* If a parsing problem occurs (invalid JSON),
2560-
* {@link JsonParseException} will be thrown.
2561-
* If no content is found from input (end-of-input), Java
2562-
* <code>null</code> will be returned.
2563-
*
2564-
* @param content JSON content to parse to build the JSON tree.
2565-
*
2566-
* @return a {@link JsonNode}, if valid JSON content found; null
2567-
* if input has no content to bind -- note, however, that if
2568-
* JSON <code>null</code> token is found, it will be represented
2569-
* as a non-null {@link JsonNode} (one that returns <code>true</code>
2570-
* for {@link JsonNode#isNull()}
2571-
*
2572-
* @throws JsonParseException if underlying input contains invalid content
2573-
* of type {@link JsonParser} supports (JSON for default case)
2537+
* Same as {@link #readTree(InputStream)} except content read from
2538+
* passed-in {@link String}
25742539
*/
25752540
public JsonNode readTree(String content) throws IOException {
25762541
return _readTreeAndClose(_jsonFactory.createParser(content));
25772542
}
25782543

25792544
/**
2580-
* Method to deserialize JSON content as tree expressed using set of {@link JsonNode} instances.
2581-
* Returns root of the resulting tree (where root can consist of just a single node if the current
2582-
* event is a value event, not container).
2583-
*
2584-
* @param content JSON content to parse to build the JSON tree.
2585-
*
2586-
* @return a {@link JsonNode}, if valid JSON content found; null
2587-
* if input has no content to bind -- note, however, that if
2588-
* JSON <code>null</code> token is found, it will be represented
2589-
* as a non-null {@link JsonNode} (one that returns <code>true</code>
2590-
* for {@link JsonNode#isNull()}
2591-
*
2592-
* @throws JsonParseException if underlying input contains invalid content
2593-
* of type {@link JsonParser} supports (JSON for default case)
2545+
* Same as {@link #readTree(InputStream)} except content read from
2546+
* passed-in byte array.
25942547
*/
25952548
public JsonNode readTree(byte[] content) throws IOException {
25962549
return _readTreeAndClose(_jsonFactory.createParser(content));
25972550
}
25982551

25992552
/**
2600-
* @since 2.10
2553+
* Same as {@link #readTree(InputStream)} except content read from
2554+
* passed-in byte array.
26012555
*/
26022556
public JsonNode readTree(byte[] content, int offset, int len) throws IOException {
26032557
return _readTreeAndClose(_jsonFactory.createParser(content, offset, len));
26042558
}
26052559

26062560
/**
2607-
* Method to deserialize JSON content as tree expressed using set of {@link JsonNode} instances.
2608-
* Returns root of the resulting tree (where root can consist of just a single node if the current
2609-
* event is a value event, not container).
2610-
*
2611-
* @param file File of which contents to parse as JSON for building a tree instance
2612-
*
2613-
* @return a {@link JsonNode}, if valid JSON content found; null
2614-
* if input has no content to bind -- note, however, that if
2615-
* JSON <code>null</code> token is found, it will be represented
2616-
* as a non-null {@link JsonNode} (one that returns <code>true</code>
2617-
* for {@link JsonNode#isNull()}
2618-
*
2619-
* @throws IOException if a low-level I/O problem (unexpected end-of-input,
2620-
* network error) occurs (passed through as-is without additional wrapping -- note
2621-
* that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS}
2622-
* does NOT result in wrapping of exception even if enabled)
2623-
* @throws JsonParseException if underlying input contains invalid content
2624-
* of type {@link JsonParser} supports (JSON for default case)
2561+
* Same as {@link #readTree(InputStream)} except content read from
2562+
* passed-in {@link File}.
26252563
*/
26262564
public JsonNode readTree(File file)
26272565
throws IOException, JsonProcessingException
@@ -2630,24 +2568,8 @@ public JsonNode readTree(File file)
26302568
}
26312569

26322570
/**
2633-
* Method to deserialize JSON content as tree expressed using set of {@link JsonNode} instances.
2634-
* Returns root of the resulting tree (where root can consist of just a single node if the current
2635-
* event is a value event, not container).
2636-
*
2637-
* @param source URL to use for fetching contents to parse as JSON for building a tree instance
2638-
*
2639-
* @return a {@link JsonNode}, if valid JSON content found; null
2640-
* if input has no content to bind -- note, however, that if
2641-
* JSON <code>null</code> token is found, it will be represented
2642-
* as a non-null {@link JsonNode} (one that returns <code>true</code>
2643-
* for {@link JsonNode#isNull()}
2644-
*
2645-
* @throws IOException if a low-level I/O problem (unexpected end-of-input,
2646-
* network error) occurs (passed through as-is without additional wrapping -- note
2647-
* that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS}
2648-
* does NOT result in wrapping of exception even if enabled)
2649-
* @throws JsonParseException if underlying input contains invalid content
2650-
* of type {@link JsonParser} supports (JSON for default case)
2571+
* Same as {@link #readTree(InputStream)} except content read from
2572+
* passed-in {@link URL}.
26512573
*/
26522574
public JsonNode readTree(URL source) throws IOException {
26532575
return _readTreeAndClose(_jsonFactory.createParser(source));

src/main/java/com/fasterxml/jackson/databind/ObjectReader.java

+27-16
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,13 @@ public JsonParser treeAsTokens(TreeNode n) {
11491149
* Convenience method that binds content read using given parser, using
11501150
* configuration of this reader, except that content is bound as
11511151
* JSON tree instead of configured root value type.
1152+
* Returns {@link JsonNode} that represents the root of the resulting tree, if there
1153+
* was content to read, or {@code null} if no more content is accessible
1154+
* via passed {@link JsonParser}.
1155+
*<p>
1156+
* NOTE! Behavior with end-of-input (no more content) differs between this
1157+
* {@code readTree} method, and all other methods that take input source: latter
1158+
* will return "missing node", NOT {@code null}
11521159
*<p>
11531160
* Note: if an object was specified with {@link #withValueToUpdate}, it
11541161
* will be ignored.
@@ -1316,6 +1323,14 @@ public <T> T readValue(DataInput src) throws IOException
13161323
/**
13171324
* Method that reads content from given input source,
13181325
* using configuration of this reader, and binds it as JSON Tree.
1326+
* Returns {@link JsonNode} that represents the root of the resulting tree, if there
1327+
* was content to read, or "missing node" (instance of {@JsonNode} for which
1328+
* {@link JsonNode#isMissingNode()} returns true, and behaves otherwise similar to
1329+
* "null node") if no more content is accessible through passed-in input source.
1330+
*<p>
1331+
* NOTE! Behavior with end-of-input (no more content) differs between this
1332+
* {@code readTree} method, and {@link #readTree(JsonParser)} -- latter returns
1333+
* {@code null} for "no content" case.
13191334
*<p>
13201335
* Note that if an object was specified with a call to
13211336
* {@link #withValueToUpdate(Object)}
@@ -1331,13 +1346,8 @@ public JsonNode readTree(InputStream in) throws IOException
13311346
}
13321347

13331348
/**
1334-
* Method that reads content from given input source,
1335-
* using configuration of this reader, and binds it as JSON Tree.
1336-
*<p>
1337-
* Note that if an object was specified with a call to
1338-
* {@link #withValueToUpdate(Object)}
1339-
* it will just be ignored; result is always a newly constructed
1340-
* {@link JsonNode} instance.
1349+
* Same as {@link #readTree(InputStream)} except content accessed through
1350+
* passed-in {@link Reader}
13411351
*/
13421352
public JsonNode readTree(Reader r) throws IOException
13431353
{
@@ -1348,13 +1358,8 @@ public JsonNode readTree(Reader r) throws IOException
13481358
}
13491359

13501360
/**
1351-
* Method that reads content from given JSON input String,
1352-
* using configuration of this reader, and binds it as JSON Tree.
1353-
*<p>
1354-
* Note that if an object was specified with a call to
1355-
* {@link #withValueToUpdate(Object)}
1356-
* it will just be ignored; result is always a newly constructed
1357-
* {@link JsonNode} instance.
1361+
* Same as {@link #readTree(InputStream)} except content read from
1362+
* passed-in {@link String}
13581363
*/
13591364
public JsonNode readTree(String json) throws IOException
13601365
{
@@ -1365,7 +1370,8 @@ public JsonNode readTree(String json) throws IOException
13651370
}
13661371

13671372
/**
1368-
* @since 2.10
1373+
* Same as {@link #readTree(InputStream)} except content read from
1374+
* passed-in byte array.
13691375
*/
13701376
public JsonNode readTree(byte[] json) throws IOException
13711377
{
@@ -1376,7 +1382,8 @@ public JsonNode readTree(byte[] json) throws IOException
13761382
}
13771383

13781384
/**
1379-
* @since 2.10
1385+
* Same as {@link #readTree(InputStream)} except content read from
1386+
* passed-in byte array.
13801387
*/
13811388
public JsonNode readTree(byte[] json, int offset, int len) throws IOException
13821389
{
@@ -1386,6 +1393,10 @@ public JsonNode readTree(byte[] json, int offset, int len) throws IOException
13861393
return _bindAndCloseAsTree(_considerFilter(_parserFactory.createParser(json, offset, len), false));
13871394
}
13881395

1396+
/**
1397+
* Same as {@link #readTree(InputStream)} except content read using
1398+
* passed-in {@link DataInput}.
1399+
*/
13891400
public JsonNode readTree(DataInput src) throws IOException
13901401
{
13911402
if (_dataFormatReaders != null) {

0 commit comments

Comments
 (0)