use convertValue instead of treeToValue(TypeReference) for Jackson < 2.16 compatibility#1250
Merged
TimothyJones merged 3 commits intocase-contract-testing:mainfrom Feb 12, 2026
Conversation
…< 2.16 compat ObjectMapper.treeToValue(TreeNode, TypeReference) was added in Jackson 2.16.0 (FasterXML/jackson-databind#4046). Projects using Jackson 2.15.x get a NoSuchMethodError at runtime. This replaces it with the equivalent readValue(JsonParser, TypeReference) pattern which works with older versions.
Member
TimothyJones
left a comment
There was a problem hiding this comment.
Thanks for this! Would mapper.convertValue work for you here? It looks like it still existed back in 2.15.3:
That way we wouldn't have to do the re-serialisaiton - which would be good as this part of the code gets hot when there are a lot of contracts.
…on < 2.16 compat Per maintainer feedback, use convertValue instead of readValue+traverse to avoid re-serialisation overhead on hot path.
Contributor
Author
Yes, that works too. Updated |
Member
|
Awesome, I'll get this merged and released today |
Member
|
Thanks again! |
TimothyJones
approved these changes
Feb 12, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ObjectMapper.treeToValue(TreeNode, TypeReference)was added in Jackson 2.16.0 (FasterXML/jackson-databind#4056). Projects that use Jackson 2.15.x get aNoSuchMethodErrorat runtime when callingprepareVerificationFix
Replaced
mapper.treeToValue(node, TypeReference)with the equivalentmapper.convertValueinVerifierResultMapper.toVerificationHandle(). This achieves the same result but works with Jackson 2.15.x and earlier.Testing
./gradlew test)NoSuchMethodErrorin a downstream project using Jackson 2.15.x