Skip to content

Commit 752cba2

Browse files
authored
Fix #4153: add missing ObjectReader.forType() overload (#4154)
1 parent c79bb5f commit 752cba2

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

release-notes/CREDITS-2.x

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,3 +1701,8 @@ Omar Aloraini (ooraini@github)
17011701
* Requested #4061: Add JsonTypeInfo.Id.SIMPLE_NAME which defaults type id
17021702
to `Class.getSimpleName()`
17031703
(2.16.0)
1704+
1705+
Garret Wilson (garretwilson@github)
1706+
* Reported #4153: Deprecated `ObjectReader.withType(Type)` has no direct
1707+
replacement; need `forType(Type)`
1708+
(2.16.0)

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ Project: jackson-databind
8686
wrt argument
8787
#4145: NPE when transforming a tree to a model class object, at `ArrayNode.elements()`
8888
(reported by Ondrej Z)
89+
#4153: Deprecated `ObjectReader.withType(Type)` has no direct replacement;
90+
need `forType(Type)`
91+
(reported by Garren W)
8992

9093
2.15.3 (not yet released)
9194

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ public ObjectReader with(FormatSchema schema)
758758
* Method for constructing a new reader instance that is configured
759759
* to data bind into specified type.
760760
*<p>
761-
* Note that the method does NOT change state of this reader, but
761+
* Note that the method does not change state of this reader, but
762762
* rather construct and returns a newly configured instance.
763763
*
764764
* @since 2.5
@@ -782,7 +782,7 @@ public ObjectReader forType(JavaType valueType)
782782
* Method for constructing a new reader instance that is configured
783783
* to data bind into specified type.
784784
*<p>
785-
* Note that the method does NOT change state of this reader, but
785+
* Note that the method does not change state of this reader, but
786786
* rather construct and returns a newly configured instance.
787787
*
788788
* @since 2.5
@@ -795,7 +795,27 @@ public ObjectReader forType(Class<?> valueType) {
795795
* Method for constructing a new reader instance that is configured
796796
* to data bind into specified type.
797797
*<p>
798-
* Note that the method does NOT change state of this reader, but
798+
* <b>WARNING!</b> Note that type resolution from {@link java.lang.reflect.Type}
799+
* may fail to properly resolve generic type declarations because it does not
800+
* pass any context (like {@code Field} or {@code Method} it is included for;
801+
* or encloding {@link Class}).
802+
* For this reason you should only use this method if you really know what
803+
* you are doing.
804+
*<p>
805+
* Note that the method does not change state of this reader, but
806+
* rather construct and returns a newly configured instance.
807+
*
808+
* @since 2.16
809+
*/
810+
public ObjectReader forType(java.lang.reflect.Type valueType) {
811+
return forType(_config.getTypeFactory().constructType(valueType));
812+
}
813+
814+
/**
815+
* Method for constructing a new reader instance that is configured
816+
* to data bind into specified type.
817+
*<p>
818+
* Note that the method does not change state of this reader, but
799819
* rather construct and returns a newly configured instance.
800820
*
801821
* @since 2.5
@@ -821,7 +841,7 @@ public ObjectReader withType(Class<?> valueType) {
821841
}
822842

823843
/**
824-
* @deprecated since 2.5 Use {@link #forType(Class)} instead
844+
* @deprecated since 2.5 Use {@link #forType(java.lang.reflect.Type)} instead
825845
*/
826846
@Deprecated
827847
public ObjectReader withType(java.lang.reflect.Type valueType) {

0 commit comments

Comments
 (0)