Skip to content

fix(core): adjust the jsonCreator Annotation for full argument constructor #756

Open
Willam2004 wants to merge 3 commits intoagentscope-ai:mainfrom
Willam2004:main
Open

fix(core): adjust the jsonCreator Annotation for full argument constructor #756
Willam2004 wants to merge 3 commits intoagentscope-ai:mainfrom
Willam2004:main

Conversation

@Willam2004
Copy link

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.8, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@Willam2004 Willam2004 requested a review from a team February 7, 2026 11:17
@gemini-code-assist
Copy link

Summary of Changes

Hello @Willam2004, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue with the JSON deserialization of ToolUseBlock objects by correctly configuring the JsonCreator annotation. The change ensures that all properties, including the content field, are properly handled during object reconstruction from JSON. Additionally, a robust suite of unit tests has been introduced to validate the serialization and deserialization logic, significantly improving the reliability of ToolUseBlock's JSON handling.

Highlights

  • JSON Deserialization Fix: The @JsonCreator annotation has been moved from the 4-argument constructor to the 5-argument constructor in ToolUseBlock.java. This ensures that Jackson correctly uses the constructor that includes the content parameter when deserializing ToolUseBlock objects from JSON, allowing for full argument reconstruction.
  • Enhanced Test Coverage: A new comprehensive test file, ToolUseBlockTest.java, has been added. This file includes extensive unit tests for JSON serialization and deserialization of ToolUseBlock under various conditions, such as all fields present, missing optional fields, null fields, and verifies the immutability of input and metadata maps. It also covers different constructor usages and the builder pattern.
Changelog
  • agentscope-core/src/main/java/io/agentscope/core/message/ToolUseBlock.java
    • Removed @JsonCreator annotation from the 4-argument constructor (id, name, input, metadata).
    • Added @JsonCreator annotation to the 5-argument constructor (id, name, input, content, metadata) and applied @JsonProperty to each parameter for explicit mapping.
  • agentscope-core/src/test/java/io/agentscope/core/message/ToolUseBlockTest.java
    • Added new unit test file ToolUseBlockTest.java to provide comprehensive test coverage for ToolUseBlock.
    • Includes tests for JSON serialization and deserialization with all fields, missing fields (content, metadata), empty input, and null content.
    • Added tests to verify round-trip serialization and deserialization consistency.
    • Implemented tests to confirm the immutability of the input and metadata maps after object creation.
    • Contains tests for various constructors (3, 4, and 5 parameters) and the builder pattern.
    • Added a test to ensure input and metadata maps are initialized as empty when nulls are passed to the constructor.
Activity
  • The pull request description contains a template, indicating that the author is expected to fill in details about the version, description, and checklist. As of now, these sections are placeholders.
  • No specific human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@cla-assistant
Copy link

cla-assistant bot commented Feb 7, 2026

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link

cla-assistant bot commented Feb 7, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly adjusts the @JsonCreator annotation in ToolUseBlock to point to the constructor with the most arguments, ensuring robust JSON deserialization for all fields. The change is well-supported by a comprehensive new test suite in ToolUseBlockTest.java, which covers various serialization and deserialization scenarios. I've added a couple of suggestions to improve the test code by using more idiomatic JUnit 5 assertions for exception testing, which will enhance readability and maintainability.

Comment on lines +195 to +200
try {
toolUseBlock.getInput().put("key3", "value3");
assertFalse(true, "Expected UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
assertTrue(true);
}

Choose a reason for hiding this comment

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

medium

For better readability and to follow modern JUnit 5 practices, it's recommended to use assertThrows to verify that an exception is thrown. This makes the test's intent clearer and more concise than a try-catch block.

        assertThrows(UnsupportedOperationException.class, () -> toolUseBlock.getInput().put("key3", "value3"));

Comment on lines +215 to +220
try {
toolUseBlock.getMetadata().put("meta3", "data3");
assertFalse(true, "Expected UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
assertTrue(true);
}

Choose a reason for hiding this comment

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

medium

Similar to the previous comment, using assertThrows is the preferred way to test for exceptions in JUnit 5. It improves the clarity and conciseness of the test.

        assertThrows(UnsupportedOperationException.class, () -> toolUseBlock.getMetadata().put("meta3", "data3"));

@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant