Skip to content

Commit 7270f49

Browse files
authored
Implement #5257: deprecate URL-taking read methods (#5258)
1 parent e40aaee commit 7270f49

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

release-notes/VERSION-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Not yet released
1212
(reported by @nlisker)
1313
#5242: Support "binary vectors": `@JsonFormat(shape = Shape.BINARY)` for
1414
`float[]`, `double[]`
15+
#5257: Deprecate `URL`-taking `readValue()` methods in `ObjectMapper`, `ObjectReader`
1516

1617
2.20.0-rc1 (04-Aug-2025)
1718

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,12 +1297,15 @@ public JsonParser createParser(File src) throws IOException {
12971297

12981298
/**
12991299
* Factory method for constructing properly initialized {@link JsonParser}
1300-
* to read content from specified {@link File}.
1300+
* to read content from specified {@link URL}.
13011301
* Parser is not managed (or "owned") by ObjectMapper: caller is responsible
13021302
* for properly closing it once content reading is complete.
13031303
*
13041304
* @since 2.11
1305+
*
1306+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
13051307
*/
1308+
@Deprecated // @since 2.20
13061309
public JsonParser createParser(URL src) throws IOException {
13071310
_assertNotNull("src", src);
13081311
return _deserializationConfig.initialize(_jsonFactory.createParser(src));
@@ -3346,11 +3349,14 @@ public JsonNode readTree(File file) throws IOException
33463349
* passed-in {@link URL}.
33473350
*<p>
33483351
* NOTE: handling of {@link java.net.URL} is delegated to
3349-
* {@link JsonFactory#createParser(java.net.URL)} and usually simply
3352+
* {@link JsonFactory#createParser(URL)} and usually simply
33503353
* calls {@link java.net.URL#openStream()}, meaning no special handling
33513354
* is done. If different HTTP connection options are needed you will need
33523355
* to create {@link java.io.InputStream} separately.
3356+
*
3357+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
33533358
*/
3359+
@Deprecated // @since 2.20
33543360
public JsonNode readTree(URL source) throws IOException
33553361
{
33563362
_assertNotNull("source", source);
@@ -3817,29 +3823,40 @@ public <T> T readValue(File src, JavaType valueType)
38173823
* of type {@link JsonParser} supports (JSON for default case)
38183824
* @throws DatabindException if the input JSON structure does not match structure
38193825
* expected for result type (or has other mismatch issues)
3826+
*
3827+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
38203828
*/
3829+
@Deprecated // @since 2.20
38213830
@SuppressWarnings("unchecked")
38223831
public <T> T readValue(URL src, Class<T> valueType)
38233832
throws IOException, StreamReadException, DatabindException
38243833
{
38253834
_assertNotNull("src", src);
3826-
return (T) _readMapAndClose(_jsonFactory.createParser(src), _typeFactory.constructType(valueType));
3835+
return (T) _readMapAndClose(_jsonFactory.createParser(src),
3836+
_typeFactory.constructType(valueType));
38273837
}
38283838

38293839
/**
38303840
* Same as {@link #readValue(java.net.URL, Class)} except that target specified by {@link TypeReference}.
3841+
*
3842+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
38313843
*/
3844+
@Deprecated // @since 2.20
38323845
@SuppressWarnings({ "unchecked" })
38333846
public <T> T readValue(URL src, TypeReference<T> valueTypeRef)
38343847
throws IOException, StreamReadException, DatabindException
38353848
{
38363849
_assertNotNull("src", src);
3837-
return (T) _readMapAndClose(_jsonFactory.createParser(src), _typeFactory.constructType(valueTypeRef));
3850+
return (T) _readMapAndClose(_jsonFactory.createParser(src),
3851+
_typeFactory.constructType(valueTypeRef));
38383852
}
38393853

38403854
/**
38413855
* Same as {@link #readValue(java.net.URL, Class)} except that target specified by {@link JavaType}.
3856+
*
3857+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
38423858
*/
3859+
@Deprecated // @since 2.20
38433860
@SuppressWarnings("unchecked")
38443861
public <T> T readValue(URL src, JavaType valueType)
38453862
throws IOException, StreamReadException, DatabindException

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,10 @@ public JsonParser createParser(File src) throws IOException {
11031103
* for properly closing it once content reading is complete.
11041104
*
11051105
* @since 2.11
1106+
*
1107+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
11061108
*/
1109+
@Deprecated // @since 2.20
11071110
public JsonParser createParser(URL src) throws IOException {
11081111
_assertNotNull("src", src);
11091112
return _config.initialize(_parserFactory.createParser(src), _schema);
@@ -1699,7 +1702,10 @@ public <T> T readValue(File src, Class<T> valueType) throws IOException
16991702
* calls {@link java.net.URL#openStream()}, meaning no special handling
17001703
* is done. If different HTTP connection options are needed you will need
17011704
* to create {@link java.io.InputStream} separately.
1705+
*
1706+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
17021707
*/
1708+
@Deprecated // @since 2.20
17031709
@SuppressWarnings("unchecked")
17041710
public <T> T readValue(URL src) throws IOException
17051711
{
@@ -1717,7 +1723,10 @@ public <T> T readValue(URL src) throws IOException
17171723
* @param valueType Target type to bind content to
17181724
*
17191725
* @since 2.11
1726+
*
1727+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
17201728
*/
1729+
@Deprecated // @since 2.20
17211730
@SuppressWarnings("unchecked")
17221731
public <T> T readValue(URL src, Class<T> valueType) throws IOException
17231732
{
@@ -2008,7 +2017,10 @@ public <T> MappingIterator<T> readValues(File src) throws IOException
20082017
* to create {@link java.io.InputStream} separately.
20092018
*
20102019
* @param src URL to read to access JSON content to parse.
2020+
*
2021+
* @deprecated since 2.20 deprecated as it calls {@link JsonFactory#createParser(URL)}.
20112022
*/
2023+
@Deprecated // @since 2.20
20122024
public <T> MappingIterator<T> readValues(URL src) throws IOException
20132025
{
20142026
if (_dataFormatReaders != null) {

0 commit comments

Comments
 (0)