Skip to content

use convertValue instead of treeToValue(TypeReference) for Jackson < 2.16 compatibility#1250

Merged
TimothyJones merged 3 commits intocase-contract-testing:mainfrom
Shaowen-Xiang:fix/jackson-2.15-compat
Feb 12, 2026
Merged

use convertValue instead of treeToValue(TypeReference) for Jackson < 2.16 compatibility#1250
TimothyJones merged 3 commits intocase-contract-testing:mainfrom
Shaowen-Xiang:fix/jackson-2.15-compat

Conversation

@Shaowen-Xiang
Copy link
Contributor

@Shaowen-Xiang Shaowen-Xiang commented Feb 11, 2026

Problem

ObjectMapper.treeToValue(TreeNode, TypeReference) was added in Jackson 2.16.0 (FasterXML/jackson-databind#4056). Projects that use Jackson 2.15.x get a NoSuchMethodError at runtime when calling prepareVerification

Fix

Replaced mapper.treeToValue(node, TypeReference) with the equivalent mapper.convertValue in VerifierResultMapper.toVerificationHandle(). This achieves the same result but works with Jackson 2.15.x and earlier.

Testing

  • contract-case tests pass (./gradlew test)
  • Verified the fix resolves the NoSuchMethodError in a downstream project using Jackson 2.15.x

…&lt; 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.
Copy link
Member

@TimothyJones TimothyJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! Would mapper.convertValue work for you here? It looks like it still existed back in 2.15.3:

https://javadoc.io/static/com.fasterxml.jackson.core/jackson-databind/2.15.3/com/fasterxml/jackson/databind/ObjectMapper.html#convertValue-java.lang.Object-com.fasterxml.jackson.core.type.TypeReference-

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.
@Shaowen-Xiang
Copy link
Contributor Author

Thanks for this! Would mapper.convertValue work for you here? It looks like it still existed back in 2.15.3:

https://javadoc.io/static/com.fasterxml.jackson.core/jackson-databind/2.15.3/com/fasterxml/jackson/databind/ObjectMapper.html#convertValue-java.lang.Object-com.fasterxml.jackson.core.type.TypeReference-

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.

Yes, that works too. Updated

@Shaowen-Xiang Shaowen-Xiang changed the title use readValue instead of treeToValue(TypeReference) for Jackson < 2.16 compatibility use convertValue instead of treeToValue(TypeReference) for Jackson < 2.16 compatibility Feb 11, 2026
@TimothyJones TimothyJones enabled auto-merge (squash) February 12, 2026 00:38
@TimothyJones
Copy link
Member

Awesome, I'll get this merged and released today

@TimothyJones
Copy link
Member

Thanks again!

@TimothyJones TimothyJones merged commit 135e04a into case-contract-testing:main Feb 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments