|
3 | 3 | import java.io.*;
|
4 | 4 | import java.lang.reflect.Type;
|
5 | 5 | import java.net.URL;
|
| 6 | +import java.nio.file.Path; |
6 | 7 | import java.text.DateFormat;
|
7 | 8 | import java.util.Collection;
|
8 | 9 | import java.util.List;
|
@@ -583,6 +584,20 @@ public JsonParser createParser(File src) throws JacksonException {
|
583 | 584 | return ctxt.assignAndReturnParser(_streamFactory.createParser(ctxt, src));
|
584 | 585 | }
|
585 | 586 |
|
| 587 | + /** |
| 588 | + * Factory method for constructing {@link JsonParser} that is properly |
| 589 | + * wired to allow callbacks for deserialization: basically |
| 590 | + * constructs a {@link ObjectReadContext} and then calls |
| 591 | + * {@link TokenStreamFactory#createParser(ObjectReadContext,Path)}. |
| 592 | + * |
| 593 | + * @since 3.0 |
| 594 | + */ |
| 595 | + public JsonParser createParser(Path src) throws JacksonException { |
| 596 | + _assertNotNull("src", src); |
| 597 | + DeserializationContextExt ctxt = _deserializationContext(); |
| 598 | + return ctxt.assignAndReturnParser(_streamFactory.createParser(ctxt, src)); |
| 599 | + } |
| 600 | + |
586 | 601 | /**
|
587 | 602 | * Factory method for constructing {@link JsonParser} that is properly
|
588 | 603 | * wired to allow callbacks for deserialization: basically
|
@@ -781,6 +796,19 @@ public JsonGenerator createGenerator(File f, JsonEncoding enc) throws JacksonExc
|
781 | 796 | return _streamFactory.createGenerator(_serializerProvider(), f, enc);
|
782 | 797 | }
|
783 | 798 |
|
| 799 | + /** |
| 800 | + * Factory method for constructing {@link JsonGenerator} that is properly |
| 801 | + * wired to allow callbacks for serialization: basically |
| 802 | + * constructs a {@link ObjectWriteContext} and then calls |
| 803 | + * {@link TokenStreamFactory#createGenerator(ObjectWriteContext,Path,JsonEncoding)}. |
| 804 | + * |
| 805 | + * @since 3.0 |
| 806 | + */ |
| 807 | + public JsonGenerator createGenerator(Path p, JsonEncoding enc) throws JacksonException { |
| 808 | + _assertNotNull("p", p); |
| 809 | + return _streamFactory.createGenerator(_serializerProvider(), p, enc); |
| 810 | + } |
| 811 | + |
784 | 812 | /**
|
785 | 813 | * Factory method for constructing {@link JsonGenerator} that is properly
|
786 | 814 | * wired to allow callbacks for serialization: basically
|
@@ -1151,6 +1179,19 @@ public JsonNode readTree(File file) throws JacksonException
|
1151 | 1179 | return _readTreeAndClose(ctxt, _streamFactory.createParser(ctxt, file));
|
1152 | 1180 | }
|
1153 | 1181 |
|
| 1182 | + /** |
| 1183 | + * Same as {@link #readTree(InputStream)} except content read from |
| 1184 | + * passed-in {@link Path}. |
| 1185 | + * |
| 1186 | + * @since 3.0 |
| 1187 | + */ |
| 1188 | + public JsonNode readTree(Path path) throws JacksonException |
| 1189 | + { |
| 1190 | + _assertNotNull("path", path); |
| 1191 | + DeserializationContextExt ctxt = _deserializationContext(); |
| 1192 | + return _readTreeAndClose(ctxt, _streamFactory.createParser(ctxt, path)); |
| 1193 | + } |
| 1194 | + |
1154 | 1195 | /**
|
1155 | 1196 | * Same as {@link #readTree(InputStream)} except content read from
|
1156 | 1197 | * passed-in {@link URL}.
|
@@ -1365,6 +1406,74 @@ public <T> T readValue(File src, JavaType valueType) throws JacksonException
|
1365 | 1406 | return (T) _readMapAndClose(ctxt, _streamFactory.createParser(ctxt, src), valueType);
|
1366 | 1407 | }
|
1367 | 1408 |
|
| 1409 | + /** |
| 1410 | + * Method to deserialize JSON content from given path into given Java type. |
| 1411 | + * |
| 1412 | + * @throws WrappedIOException if a low-level I/O problem (unexpected end-of-input, |
| 1413 | + * network error) occurs (passed through as-is without additional wrapping -- note |
| 1414 | + * that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS} |
| 1415 | + * does NOT result in wrapping of exception even if enabled) |
| 1416 | + * @throws StreamReadException if underlying input contains invalid content |
| 1417 | + * of type {@link JsonParser} supports (JSON for default case) |
| 1418 | + * @throws DatabindException if the input JSON structure does not match structure |
| 1419 | + * expected for result type (or has other mismatch issues) |
| 1420 | + * |
| 1421 | + * @since 3.0 |
| 1422 | + */ |
| 1423 | + @SuppressWarnings("unchecked") |
| 1424 | + public <T> T readValue(Path src, Class<T> valueType) throws JacksonException |
| 1425 | + { |
| 1426 | + _assertNotNull("src", src); |
| 1427 | + DeserializationContextExt ctxt = _deserializationContext(); |
| 1428 | + return (T) _readMapAndClose(ctxt, _streamFactory.createParser(ctxt, src), |
| 1429 | + _typeFactory.constructType(valueType)); |
| 1430 | + } |
| 1431 | + |
| 1432 | + /** |
| 1433 | + * Method to deserialize JSON content from given path into given Java type. |
| 1434 | + * |
| 1435 | + * @throws WrappedIOException if a low-level I/O problem (unexpected end-of-input, |
| 1436 | + * network error) occurs (passed through as-is without additional wrapping -- note |
| 1437 | + * that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS} |
| 1438 | + * does NOT result in wrapping of exception even if enabled) |
| 1439 | + * @throws StreamReadException if underlying input contains invalid content |
| 1440 | + * of type {@link JsonParser} supports (JSON for default case) |
| 1441 | + * @throws DatabindException if the input JSON structure does not match structure |
| 1442 | + * expected for result type (or has other mismatch issues) |
| 1443 | + * |
| 1444 | + * @since 3.0 |
| 1445 | + */ |
| 1446 | + @SuppressWarnings({ "unchecked" }) |
| 1447 | + public <T> T readValue(Path src, TypeReference<T> valueTypeRef) throws JacksonException |
| 1448 | + { |
| 1449 | + _assertNotNull("src", src); |
| 1450 | + DeserializationContextExt ctxt = _deserializationContext(); |
| 1451 | + return (T) _readMapAndClose(ctxt, _streamFactory.createParser(ctxt, src), |
| 1452 | + _typeFactory.constructType(valueTypeRef)); |
| 1453 | + } |
| 1454 | + |
| 1455 | + /** |
| 1456 | + * Method to deserialize JSON content from given path into given Java type. |
| 1457 | + * |
| 1458 | + * @throws WrappedIOException if a low-level I/O problem (unexpected end-of-input, |
| 1459 | + * network error) occurs (passed through as-is without additional wrapping -- note |
| 1460 | + * that this is one case where {@link DeserializationFeature#WRAP_EXCEPTIONS} |
| 1461 | + * does NOT result in wrapping of exception even if enabled) |
| 1462 | + * @throws StreamReadException if underlying input contains invalid content |
| 1463 | + * of type {@link JsonParser} supports (JSON for default case) |
| 1464 | + * @throws DatabindException if the input JSON structure does not match structure |
| 1465 | + * expected for result type (or has other mismatch issues) |
| 1466 | + * |
| 1467 | + * @since 3.0 |
| 1468 | + */ |
| 1469 | + @SuppressWarnings("unchecked") |
| 1470 | + public <T> T readValue(Path src, JavaType valueType) throws JacksonException |
| 1471 | + { |
| 1472 | + _assertNotNull("src", src); |
| 1473 | + DeserializationContextExt ctxt = _deserializationContext(); |
| 1474 | + return (T) _readMapAndClose(ctxt, _streamFactory.createParser(ctxt, src), valueType); |
| 1475 | + } |
| 1476 | + |
1368 | 1477 | /**
|
1369 | 1478 | * Method to deserialize JSON content from given resource into given Java type.
|
1370 | 1479 | *<p>
|
@@ -1628,6 +1737,20 @@ public void writeValue(File file, Object value) throws JacksonException
|
1628 | 1737 | _streamFactory.createGenerator(prov, file, JsonEncoding.UTF8), value);
|
1629 | 1738 | }
|
1630 | 1739 |
|
| 1740 | + /** |
| 1741 | + * Method that can be used to serialize any Java value as |
| 1742 | + * JSON output, written to Path provided. |
| 1743 | + * |
| 1744 | + * @since 3.0 |
| 1745 | + */ |
| 1746 | + public void writeValue(Path path, Object value) throws JacksonException |
| 1747 | + { |
| 1748 | + _assertNotNull("path", path); |
| 1749 | + SerializationContextExt prov = _serializerProvider(); |
| 1750 | + _configAndWriteValue(prov, |
| 1751 | + _streamFactory.createGenerator(prov, path, JsonEncoding.UTF8), value); |
| 1752 | + } |
| 1753 | + |
1631 | 1754 | /**
|
1632 | 1755 | * Method that can be used to serialize any Java value as
|
1633 | 1756 | * JSON output, using output stream provided (using encoding
|
|
0 commit comments