-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide/document alternative to TypeFactory#constructType(Type type, Class<?> contextType) in 2.7 #1087
Comments
Removal was accidental, as per #1079; I will add it back as deprecated for 2.7.1. This is the way it should have been in 2.7.0. Apologies for that. Now, as to replacement method... the problem with method was that the full type resolution context can not be fully created with given parameters. For specific case of method parameter or return types, or field types, what is needed is the type of declaring Let me know if you have trouble figuring out replacement(s); this is bit tricky area. But on plus side, type resolution should FINALLY work the way it should always have -- there are no open issues related to type variable aliasing or other resolution issues. So I don't anticipate breaking changes in this area for future minor releases. |
Thanks for your feedback, and thanks for add it back in 2.7.1 as deprecated. For the replacement method (since our goal in Spring 4.3 is to avoid using deprecated methods when Jackson 2.7 is used), I have changed: protected JavaType getJavaType(Type type, Class<?> contextClass) {
TypeFactory typeFactory = this.objectMapper.getTypeFactory();
return typeFactory.constructType(type, contextClass)
} To protected JavaType getJavaType(Type type, Class<?> contextClass) {
TypeFactory typeFactory = this.objectMapper.getTypeFactory();
Type superclass = (contextClass == null ? null : contextClass.getGenericSuperclass());
TypeBindings bindings = (superclass == null ? TypeBindings.emptyBindings() :
typeFactory.constructType(superclass).getBindings());
return typeFactory.constructType(type, bindings);
} It seems to work well in our unit tests (I will do more tests with various use cases). Is it what you had in mind in you first proposal? |
@sdeleuze close; I think resolving of Anyway, if code you have works fine, it is probably reasonable thing to use. |
In fact, I initially tried resolving directly To give you more details, here is my use case. I have the following controller classes: public abstract class MyParameterizedController<DTO extends Identifiable> {
public void handleDto(HttpEntity<DTO> dto) {}
}
public class MySimpleParameterizedController extends MyParameterizedController<SimpleBean> {
} In that test, we try to resolve the generic parameter of the method retrieved thanks to Both Jackson 2.6 But if I resolve directly |
@sdeleuze Well, keep in mind that the method as is deprecated for the reason it can not actually be fully implemented with information given: it is possible to pass inconsistent arguments, but no way to really detect whether they are or are not compatible. So change to replace that on caller side needs to be bigger. Problem is often that method itself may not have enough context to do such decision. In your specific case, resolution should start with The reason type parameters from I hope my explanation at least points in right direction... it's bit difficult to explain. But basically active type parameter name to resolved type bindings vary between layers of inheritance hierarchy; older code assumed there's one flat binding, but this is not true. Now that layers are exactly resolved, it is however necessary to find the proper layer. It can be more work, but on plus side it actually then fully works. |
Thanks for your detailed feedback, much appreciated. |
AbstractJackson2HttpMessageConverter now implements its own TypeVariable resolution algorithm since it is now deprecated and has not the same behavior in Jackson 2.7. See FasterXML/jackson-databind#1087 for more details. The dependency on jackson-datatype-jdk7 has been removed since it is now provided by default in jackson-databind. Issues: SPR-13483, SPR-13728
I have implemented the |
@sdeleuze Thank you for working through this, and apologies for the hassle. As I said, I hope to keep API stable in this are from this point on. |
…bindings from that are expected to work.
AbstractJackson2HttpMessageConverter now implements its own TypeVariable resolution algorithm since in Jackson 2.7 it is now deprecated and has not the same behavior . See FasterXML/jackson-databind#1087 for more details. The dependency on jackson-datatype-jdk7 has been removed since it is now provided by default in the jackson-databind module. Issues: SPR-13483, SPR-13728
# By Tatu Saloranta (113) and others # Via Tatu Saloranta * 'master' of https://github.com/FasterXML/jackson-databind: (124 commits) Minor addition related to FasterXML#1087: resolve context type, assuming type bindings from that are expected to work. Add unit test for FasterXML#999 minor warnings cleanup Add Javadoc badge with automatic version detection Fix FasterXML#1083 Add failing test for FasterXML#1083 add a unit test to verify that Object Id works via AtomicReference too Minor javadoc improvement wrt FasterXML#1076, making `SimpleType.construct(Class)` deprecated (was not yet, for some reason, should have been) Fix FasterXML#1078 Fix FasterXML#1079 [maven-release-plugin] prepare for next development iteration [maven-release-plugin] prepare release jackson-databind-2.7.0 prepare for 2.7.0 final Fix FasterXML#1073 Try to reproduce FasterXML#1074 javadoc trimming Try to reproduce FasterXML#825 again, still passes. minor improvement to ensure base64 encoding uses configured setting Undo part of change done for StringDeserializer; caused issues with XML handling further minor cleanups to cleanup ...
In Spring Framework 4.2 and previous versions, we are using
TypeFactory#constructType(Type type, Class<?> contextType)
that is now removed in Jackson 2.7, and usingTypeFactory#constructType(Type type)
is not enough since it doesn't work for some of our use cases with parametrized Spring MVC controllers.Is there an alternative to
TypeFactory#constructType(Type type, Class<?> contextType)
in Jackson 2.7? The code for this method is still there but commented, any chance to restore it in 2.7.1 to avoid breaking all applications using Spring Framework 4.x + Jackson 2.7?The text was updated successfully, but these errors were encountered: