Skip to content

Conversation

@lbar
Copy link
Contributor

@lbar lbar commented Nov 27, 2025

Description

The library currently supports using Jackson to verify JSON objects. A new version of Jackson (3.x) has been released with API changes. The current JsonJacksonApprovals class cannot be used.

The solution

I created a new class, JsonJackson3Approvals, which has the same API as the current JsonJacksonApprovals class, in order to provide support for this new version. The same tests are also provided.

Summary by Sourcery

Add Jackson 3 JSON verification support alongside existing Jackson 2 integration.

New Features:

  • Introduce JsonJackson3Approvals to support JSON verification using Jackson 3 with an API parallel to the existing Jackson 2 helper.

Enhancements:

  • Add Jackson 3 ObjectMapper builder customization support when verifying JSON output.

Build:

  • Add Jackson 3 BOM and jackson-databind dependencies to the main and test POMs to manage Jackson 3 versions.

Tests:

  • Add JsonJackson3Approvals tests and approved JSON files to validate behavior and ensure compatibility with Jackson 3.

Copilot AI review requested due to automatic review settings November 27, 2025 14:39
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 27, 2025

Reviewer's Guide

Adds parallel support for Jackson 3.x JSON verification by introducing a new JsonJackson3Approvals helper, wiring in Jackson 3 dependencies, and duplicating the existing Jackson 2 tests for the new implementation.

File-Level Changes

Change Details Files
Introduce JsonJackson3Approvals utility to support Jackson 3.x JSON serialization and approvals.
  • Create JsonJackson3Approvals class mirroring the existing JsonJacksonApprovals API but implemented with tools.jackson.databind.JsonMapper and JacksonException from Jackson 3
  • Implement overloads for verifyAsJson and asJson that accept an optional Options parameter and a JsonMapper.Builder customization function
  • Wrap JacksonException in an unchecked error using ObjectUtils.throwAsError and use Approvals.verify with .json file extension
approvaltests/src/main/java/org/approvaltests/JsonJackson3Approvals.java
Add Jackson 3.x dependencies and BOM management for both main module and tests.
  • Introduce dependencyManagement section importing tools.jackson:jackson-bom:3.0.2 in both approvaltests and approvaltests-tests POMs
  • Add tools.jackson.core:jackson-databind:3.0.2 as a test dependency alongside the existing Jackson 2 dependency in approvaltests-tests
  • Add tools.jackson.core:jackson-databind as an optional runtime dependency in the main approvaltests module
approvaltests/pom.xml
approvaltests-tests/pom.xml
Add tests and golden files to validate JsonJackson3Approvals behavior, including mapper customization and duplicate field handling.
  • Create JsonJackson3ApprovalsTest that exercises default verification, a JsonMapper.Builder customization, and duplicate field handling via Jackson 3 annotations
  • Define inner test classes MyClass and MyOtherClass with JsonIgnore and overridden getters to validate duplicate field resolution
  • Add approved .json files for testDuplicateFields and testObjectMapperOverride to lock in the Jackson 3 serialization format
approvaltests-tests/src/test/java/org/approvaltests/JsonJackson3ApprovalsTest.java
approvaltests-tests/src/test/java/org/approvaltests/JsonJackson3ApprovalsTest.testDuplicateFields.approved.json
approvaltests-tests/src/test/java/org/approvaltests/JsonJackson3ApprovalsTest.testObjectMapperOverride.approved.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • JsonJackson3Approvals closely mirrors JsonJacksonApprovals; consider extracting a shared internal helper (e.g., a generic JsonApprovals that takes mapper types) to avoid duplication and keep the two implementations behaviorally aligned over time.
  • You’ve added a Jackson 3 BOM and explicit jackson-databind versions in both approvaltests and approvaltests-tests POMs; consider centralizing the BOM in a parent or one module and relying on dependencyManagement to avoid duplicating version declarations.
  • In JsonJackson3Approvals.verifyAsJson, you always force the .json extension via options.forFile().withExtension(".json"); if callers might want to customize the extension, consider only setting a default when no extension has been provided.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- JsonJackson3Approvals closely mirrors JsonJacksonApprovals; consider extracting a shared internal helper (e.g., a generic `JsonApprovals` that takes mapper types) to avoid duplication and keep the two implementations behaviorally aligned over time.
- You’ve added a Jackson 3 BOM and explicit `jackson-databind` versions in both `approvaltests` and `approvaltests-tests` POMs; consider centralizing the BOM in a parent or one module and relying on dependencyManagement to avoid duplicating version declarations.
- In `JsonJackson3Approvals.verifyAsJson`, you always force the `.json` extension via `options.forFile().withExtension(".json")`; if callers might want to customize the extension, consider only setting a default when no extension has been provided.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for Jackson 3.x by creating a new JsonJackson3Approvals class alongside the existing JsonJacksonApprovals class for Jackson 2.x. Jackson 3.x introduced breaking API changes including a package rename from com.fasterxml.jackson to tools.jackson, requiring a separate implementation.

Key changes:

  • New JsonJackson3Approvals utility class using Jackson 3.x's JsonMapper.Builder API
  • Jackson 3.x BOM and dependencies added to both main and test projects
  • Test suite mirroring the existing Jackson 2.x tests

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
approvaltests/src/main/java/org/approvaltests/JsonJackson3Approvals.java New utility class providing JSON approval testing with Jackson 3.x, using the new tools.jackson package and JsonMapper.Builder API
approvaltests/pom.xml Adds Jackson 3.x BOM in dependency management and jackson-databind dependency
approvaltests-tests/src/test/java/org/approvaltests/JsonJackson3ApprovalsTest.java Test suite for Jackson 3.x functionality with ObjectMapper override and duplicate fields tests
approvaltests-tests/src/test/java/org/approvaltests/JsonJackson3ApprovalsTest.testObjectMapperOverride.approved.json Expected output for ObjectMapper override test
approvaltests-tests/src/test/java/org/approvaltests/JsonJackson3ApprovalsTest.testDuplicateFields.approved.json Expected output for duplicate fields test
approvaltests-tests/pom.xml Adds Jackson 3.x BOM and jackson-databind dependency for testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +3 to +4
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The test is importing Jackson 2.x annotations (com.fasterxml.jackson.*) instead of Jackson 3.x annotations (tools.jackson.*). For Jackson 3.x, the imports should be:

  • import tools.jackson.annotation.JsonIgnore;
  • import tools.jackson.annotation.JsonInclude;

This will cause compilation errors or runtime issues when trying to use Jackson 3.x specific features.

Suggested change
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import tools.jackson.annotation.JsonIgnore;
import tools.jackson.annotation.JsonInclude;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no jackson-annotations dep for jackson 3.

Please read the note :

NOTE: jackson-annotations not affected as Jackson 3.0 uses 2.x variant (2.20) of jackson-annotations.

(https://github.com/FasterXML/jackson/wiki/Jackson-Release-3.0)

Comment on lines 141 to 144
<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>3.0.2</version>
</dependency>
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

Missing Jackson 3.x annotations dependency. Since the test uses Jackson 3.x annotations like @JsonIgnore and @JsonInclude, the following dependency should be added:

<dependency>
    <groupId>tools.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
</dependency>

This dependency will be managed by the jackson-bom declared in the dependencyManagement section.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no jackson-annotations dep for jackson 3.

Please read the note :

NOTE: jackson-annotations not affected as Jackson 3.0 uses 2.x variant (2.20) of jackson-annotations.

(https://github.com/FasterXML/jackson/wiki/Jackson-Release-3.0)

<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>3.0.2</version>
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The version should be removed from this dependency declaration since it's already managed by the jackson-bom in the dependencyManagement section (lines 20-26). This ensures version consistency across all Jackson 3.x artifacts and simplifies maintenance.

Suggested change
<version>3.0.2</version>

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

</dependency>
<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The Jackson 3.x dependency should be marked as <optional>true</optional> to maintain consistency with the Jackson 2.x dependency (line 93) and other similar optional dependencies like gson, xstream, etc. This ensures that users of the library aren't forced to include Jackson 3.x if they don't use this feature.

Suggested change
<artifactId>jackson-databind</artifactId>
<artifactId>jackson-databind</artifactId>
<optional>true</optional>

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@lbar lbar force-pushed the feat/jackson3-support branch from 8695361 to 6767dae Compare November 27, 2025 14:52
@LarsEckart
Copy link
Contributor

hey, thank you for this contribution. We'll get together on Monday 18 o'clock Central European Time and will have a look. If you also want to join, to say hello, I can forward you an invite.

@lbar
Copy link
Contributor Author

lbar commented Dec 1, 2025

Thanks for the invitation, but unfortunately, I am not available this time.

@LarsEckart LarsEckart merged commit ec0ccc0 into approvals:master Dec 1, 2025
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