Repository navigation
Description
Marek Wiącek opened SPR-13853 and commented
RestTemplate produces the following error when used with Jackson 2.7.0-rc3:
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.type.TypeFactory.constructType(Ljava/lang/reflect/Type;Ljava/lang/Class;)Lcom/fasterxml/jackson/databind/JavaType;
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.getJavaType(AbstractJackson2HttpMessageConverter.java:314)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canRead(AbstractJackson2HttpMessageConverter.java:146)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.canRead(AbstractJackson2HttpMessageConverter.java:141)
at org.springframework.web.client.RestTemplate$AcceptHeaderRequestCallback.doWithRequest(RestTemplate.java:706)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:594)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:289)
Affects: 4.2.3, 4.2.4
Issue Links:
- AbstractJackson2HttpMessageConverter is incompatible with Jackson 2.7+ [SPR-13870] #18443 AbstractJackson2HttpMessageConverter is incompatible with Jackson 2.7+ ("is duplicated by")
- Jackson 2.7.0 not compatible with Spring [SPR-13864] #18437 Jackson 2.7.0 not compatible with Spring ("is duplicated by")
- Jackson 2.6: message converter should use type only for collections [SPR-13318] #17903 Jackson 2.6: message converter should use type only for collections
- Revise AbstractJackson2HttpMessageConverter's generic type adaptation [SPR-13728] #18301 Revise AbstractJackson2HttpMessageConverter's generic type adaptation
Referenced from: commits 09db26a
1 votes, 9 watchers
Activity
spring-projects-issues commentedon Jan 9, 2016
Juergen Hoeller commented
We are aware of this already but unfortunately can't fix this easily since there is no immediate replacement for that particular
TypeFactorymethod, and in particular no known option that works on both Jackson 2.6 and 2.7 at least. #17869 tracks our effort to address this for 4.3.Juergen
spring-projects-issues commentedon Jan 10, 2016
Juergen Hoeller commented
To be clear, this means that the current Spring Framework 4.2.x generation is likely to remain incompatible with Jackson 2.7+ and will rather just keep supporting Jackson 2.1 to 2.6. As of Spring Framework 4.3, we intend to raise this to Jackson 2.6+, with first-class support for Jackson 2.7 and the upcoming 2.8... and avoiding the use of deprecated Jackson API etc so the chances of working with future Jackson versions are as high as possible. Spring Framework 4.3.x will the retain that Jackson 2.6+ baseline for its entire extended support life.
Juergen
spring-projects-issues commentedon Jan 15, 2016
Abhijit Sarkar commented
@JuergenHoeller, when can we expect 4.3 to be released? I see a SNAPSHOT out there.spring-projects-issues commentedon Jan 15, 2016
Juergen Hoeller commented
You can always check https://jira.spring.io/browse/SPR/?selectedTab=com.atlassian.jira.jira-projects-plugin:roadmap-panel for the current dates. At this point, 4.3 RC1 is scheduled for mid March, with GA expected for early May.
Is there a specific need for Jackson 2.7 on your side, beyond what Jackson 2.6.4 can do for you?
Juergen
spring-projects-issues commentedon Jan 15, 2016
Abhijit Sarkar commented
We were on Jackson 2.5 and needed this -
mapper.enable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID)After the issue with Jackson 2.7, I found out that 2.6.4 also has this attribute so I can live with that. However, as a general rule, I try not to write software that only works with a certain dependency version. I'll wait until the fix comes out to upgrade Spring as well as Jackson.
Thanks for your response.
spring-projects-issues commentedon Feb 4, 2016
Elad Tabak commented
I'm facing a similar issue, using spring 4.2.4 (latest) and jackson 2.7.1 (also latest).
Only I'm getting this exception:
I was able to identify that the AbstractJackson2HttpMessageConverter.getJavaType() method on line 249 sends the second argument as null, instead of providing the class of the object/value as needed. Using a debugger I managed to change the null with the object class, and it worked.
This seems to be an easy fix for future versions of spring, to support jackson 2.7.1+.
Any chance to fix this in future versions?
It also relates to this bug that does not seem to be resolved in spring 4.2.4, as the second argument is still null:
#17903
spring-projects-issues commentedon Feb 4, 2016
Juergen Hoeller commented
Indeed, Jackson 2.6's
constructType(Type, Class)variant accepts anullvalue for the latter argument, but Jackson 2.7.1's reintroduced method of that signature insists on the second argument to be non-null. I guess we could simply callconstructType(Type)if the context class isnullwhich would restore Jackson 2.6 behavior. Let's try that for 4.2.5.At the same time, 4.3 features a refactored approach where this problem doesn't appear anymore: see #18301. This needs to go through the 4.3 RC phase yet though.
Juergen
spring-projects-issues commentedon Feb 11, 2016
Sébastien Deleuze commented
This commit introduces the conditional call proposed by Juergen Hoeller in
AbstractJackson2HttpMessageConverter#getJavaType()in order to avoid callingTypeFactory#constructType()with anullcontextClassparameter, since this is not supported by Jackson 2.7 anymore.It allows to use Spring Framework 4.2.x with Jackson 2.7.1+ for most use cases, but with some limitations. For example, with Jackson 2.7
TypeVariableresolution from method parameters does not work.As a consequence, after this commit Spring Framework 4.2.x still fully supports Jackson up to version 2.6, but improves Jackson 2.7 compatibility. Full support for Jackson 2.7 is provided as of Spring Framework 4.3.x.
spring-projects-issues commentedon Feb 11, 2016
Elad Tabak commented
Sébastien thank you very much for the quick fix!
spring-projects-issues commentedon Feb 11, 2016
Sébastien Deleuze commented
Juergen Hoeller I just found this Jackson issue that shows that Jackson 2.7.2 will work fine with
nullcontextClass, so I am wondering if we should not revert the commit I pushed (except the Javadoc changes). Any thoughts?spring-projects-issues commentedon Feb 11, 2016
Juergen Hoeller commented
I guess since that code is just more defensive but otherwise functionally equivalent, there's nothing wrong with keeping it either?
spring-projects-issues commentedon Feb 11, 2016
Sébastien Deleuze commented
Indeed, and since we are not sure when Jackson 2.7.2 will be released, it still can help users.