-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Describe your Issue
The latest Jackson databind 2.15.2 deprecates ObjectReader.withType(java.lang.reflect.Type valueType)
. The API documentation says:
Use {@link #forType(Class)} instead
However ObjectReader.forType(Class<?> valueType)
is not a direct replacement, as not all Type
instances are Class
instances.
For example, let's say I want to unmashal some JSON to match the type of a method parameter. (This follows some discussion on FasterXML/java-classmate#69.) With the deprecated method I could do this:
Type parameter1Type = method.getGenericParameterTypes()[0];
ObjectReader typeAwareObjectReader = objectReader.withType(parameter1Type);
But now that the method ObjectReader.withType(java.lang.reflect.Type valueType)
is deprecated and going away, I'll have to do this:
Type parameter1Type = method.getGenericParameterTypes()[0];
JavaType parameter1JavaType = objectReader.getConfig().getTypeFactory().constructType(parameter1Type);
ObjectReader typeAwareObjectReader = objectReader.forType(parameter1JavaType);
An extra step with no benefit of doing it manually. (It is included as part of the deprecated ObjectReader.withType(java.lang.reflect.Type valueType)
.)
Is there any reason not to have an ObjectReader.forType(java.lang.reflect.Type valueType)
like the one that is going away, just with this better name?