Skip to content

Commit

Permalink
Fix #4153: add missing ObjectReader.forType() overload (#4154)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder authored Oct 10, 2023
1 parent c79bb5f commit 752cba2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -1701,3 +1701,8 @@ Omar Aloraini (ooraini@github)
* Requested #4061: Add JsonTypeInfo.Id.SIMPLE_NAME which defaults type id
to `Class.getSimpleName()`
(2.16.0)
Garret Wilson (garretwilson@github)
* Reported #4153: Deprecated `ObjectReader.withType(Type)` has no direct
replacement; need `forType(Type)`
(2.16.0)
3 changes: 3 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ Project: jackson-databind
wrt argument
#4145: NPE when transforming a tree to a model class object, at `ArrayNode.elements()`
(reported by Ondrej Z)
#4153: Deprecated `ObjectReader.withType(Type)` has no direct replacement;
need `forType(Type)`
(reported by Garren W)

2.15.3 (not yet released)

Expand Down
28 changes: 24 additions & 4 deletions src/main/java/com/fasterxml/jackson/databind/ObjectReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ public ObjectReader with(FormatSchema schema)
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* Note that the method does not change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
Expand All @@ -782,7 +782,7 @@ public ObjectReader forType(JavaType valueType)
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* Note that the method does not change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
Expand All @@ -795,7 +795,27 @@ public ObjectReader forType(Class<?> valueType) {
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does NOT change state of this reader, but
* <b>WARNING!</b> Note that type resolution from {@link java.lang.reflect.Type}
* may fail to properly resolve generic type declarations because it does not
* pass any context (like {@code Field} or {@code Method} it is included for;
* or encloding {@link Class}).
* For this reason you should only use this method if you really know what
* you are doing.
*<p>
* Note that the method does not change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.16
*/
public ObjectReader forType(java.lang.reflect.Type valueType) {
return forType(_config.getTypeFactory().constructType(valueType));
}

/**
* Method for constructing a new reader instance that is configured
* to data bind into specified type.
*<p>
* Note that the method does not change state of this reader, but
* rather construct and returns a newly configured instance.
*
* @since 2.5
Expand All @@ -821,7 +841,7 @@ public ObjectReader withType(Class<?> valueType) {
}

/**
* @deprecated since 2.5 Use {@link #forType(Class)} instead
* @deprecated since 2.5 Use {@link #forType(java.lang.reflect.Type)} instead
*/
@Deprecated
public ObjectReader withType(java.lang.reflect.Type valueType) {
Expand Down

0 comments on commit 752cba2

Please sign in to comment.