Skip to content

Improve Jackson 2.7 compatibility [SPR-13853] #18426

Closed

Description

@spring-projects-issues

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:

Referenced from: commits 09db26a

1 votes, 9 watchers

Activity

  1. spring-projects-issues commented on Jan 9, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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 TypeFactory method, 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

  2. spring-projects-issues commented on Jan 10, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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

  3. spring-projects-issues commented on Jan 15, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Abhijit Sarkar commented

    @Juergen Hoeller, when can we expect 4.3 to be released? I see a SNAPSHOT out there.

  4. spring-projects-issues commented on Jan 15, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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

  5. spring-projects-issues commented on Jan 15, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Abhijit Sarkar commented

    Is there a specific need for Jackson 2.7 on your side

    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.

  6. spring-projects-issues commented on Feb 4, 2016

    @spring-projects-issues
    CollaboratorAuthor

    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:

    java.lang.IllegalArgumentException: Unrecognized Type: [null]
    	com.fasterxml.jackson.databind.type.TypeFactory._fromAny(TypeFactory.java:1109)
    	com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:566)
    	com.fasterxml.jackson.databind.type.TypeFactory.constructType(TypeFactory.java:602)
    	org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.getJavaType(AbstractJackson2HttpMessageConverter.java:311)
    	org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:249)
    	org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:100)

    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

  7. spring-projects-issues commented on Feb 4, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Indeed, Jackson 2.6's constructType(Type, Class) variant accepts a null value 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 call constructType(Type) if the context class is null which 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

  8. spring-projects-issues commented on Feb 11, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    This commit introduces the conditional call proposed by Juergen Hoeller in AbstractJackson2HttpMessageConverter#getJavaType() in order to avoid calling TypeFactory#constructType() with a null contextClass parameter, 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 TypeVariable resolution 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.

  9. spring-projects-issues commented on Feb 11, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Elad Tabak commented

    Sébastien thank you very much for the quick fix!

  10. spring-projects-issues commented on Feb 11, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Juergen Hoeller I just found this Jackson issue that shows that Jackson 2.7.2 will work fine with null contextClass, so I am wondering if we should not revert the commit I pushed (except the Javadoc changes). Any thoughts?

  11. spring-projects-issues commented on Feb 11, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I guess since that code is just more defensive but otherwise functionally equivalent, there's nothing wrong with keeping it either?

  12. spring-projects-issues commented on Feb 11, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Indeed, and since we are not sure when Jackson 2.7.2 will be released, it still can help users.

  13. added
    type: enhancement
    in: web
    on Jan 11, 2019
  14. added this to the 4.2.5 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions