fix: upgrade jsonschema-generator to 5.0.0 for Spring AI 2.0.0-M4 compatibility#1355
fix: upgrade jsonschema-generator to 5.0.0 for Spring AI 2.0.0-M4 compatibility#1355xseruer wants to merge 12 commits into
Conversation
…patibility Resolves the dependency conflict between AgentScope and Spring AI 2.0.0-M4 caused by incompatible versions of com.github.victools:jsonschema-generator. Spring AI 2.0.0-M4 requires jsonschema-generator 5.0.0 which uses Jackson 3.x (tools.jackson.core). When both libraries coexist on the classpath, Maven resolves to v5.0.0, causing NoSuchMethodError in AgentScope's schema generation code that was compiled against v4.38.0 (Jackson 2.x). Changes: - Upgrade jsonschema-generator from 4.38.0 to 5.0.0 - Add tools.jackson.core:jackson-databind dependency (Jackson 3.x) - Adapt JsonSchemaUtils to bridge between Jackson 3.x (used by schema generator) and Jackson 2.x (used by the rest of AgentScope) via JSON string serialization - Update ToolSchemaModuleTest to use tools.jackson.databind.JsonNode Closes agentscope-ai#1271
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR cleanly resolves the Jackson 3 / jsonschema-generator 5.0.0 transition required for Spring AI 2.0.0-M4 coexistence. The bridge approach in JsonSchemaUtils (serialize Jackson 3 JsonNode.toString() then re-parse via Jackson 2 codec) is a pragmatic choice that keeps Jackson 2 dominant in the codebase while only exposing Jackson 3 inside the schema generator boundary. The BOM cleanup (removing the now-irrelevant jackson-core exclusion) is correct, and the dependency additions are explicit/defensive. One concern: the PR also bumps com.networknt:json-schema-validator from 2.0.0 → 3.0.0 (itself a Jackson 3 migration, per its 3.0.0 release notes) but this is not mentioned in the title or description; reviewers/users will want this called out since ToolValidator exercises that library at runtime and the new test plan only covers schema generation. Otherwise the change is well-scoped, the test import update is correct, and there are no behavioral red flags.
| <nacos-client.version>3.2.1-2026.03.30</nacos-client.version> | ||
| <json-schema-validator.version>2.0.0</json-schema-validator.version> | ||
| <jsonschema-generator.version>4.38.0</jsonschema-generator.version> | ||
| <json-schema-validator.version>3.0.0</json-schema-validator.version> |
There was a problem hiding this comment.
[minor] This PR also bumps com.networknt:json-schema-validator 2.0.0 → 3.0.0, which is a separate library from victools jsonschema-generator and itself a major release that internally moves to Jackson 3 (per its 3.0.0 release notes). The PR title and description only mention jsonschema-generator, so this bundled upgrade is easy to miss. ToolValidator (the only consumer) is not modified and its class names (SchemaRegistry, Schema, Error, InputFormat) appear unchanged, but please either (a) document the validator upgrade in the PR description with a brief note that the existing schema-validation tests still pass, or (b) split it into a separate commit/PR — this aids future bisecting if a validator-side regression surfaces.
| import java.util.List; | ||
| import java.util.stream.StreamSupport; | ||
| import org.junit.jupiter.api.Test; | ||
| import tools.jackson.databind.JsonNode; |
There was a problem hiding this comment.
[nit] While migrating this test to the Jackson 3 JsonNode, the existing .asText() calls in requiredList(...) and the assertEquals(... .asText()) assertions remain. In Jackson 3.x asText() is @Deprecated (delegates to asString()). Compilation still works, but consider switching to asString() in this file as part of the same migration to silence deprecation warnings and align with the Jackson 3 idiom. Not blocking.
| public static Map<String, Object> generateSchemaFromClass(Class<?> clazz) { | ||
| try { | ||
| JsonNode schemaNode = schemaGenerator.generateSchema(clazz); | ||
| String schemaJson = schemaGenerator.generateSchema(clazz).toString(); |
There was a problem hiding this comment.
[nit] Minor observation (not blocking): schemaGenerator.generateSchema(clazz).toString() + fromJson(...) round-trips the entire schema through a JSON string. For one-shot schema generation per Class/Type (called from ToolSchemaGenerator and StructuredOutputCapableAgent) this overhead is negligible, and the chosen approach is the cleanest way to keep Jackson 2 dominant elsewhere — so this is fine as-is. The alternative would be a dedicated Jackson 3 ObjectMapper doing convertValue(node, Map.class) directly, but that would couple JsonSchemaUtils to Jackson 3 internals, which is arguably worse. Recommended to keep the current bridge but add a brief inline comment explaining the rationale so future maintainers don't try to 'optimize' it back.
Summary
Resolves the dependency conflict between AgentScope and Spring AI 2.0.0-M4 caused by incompatible versions of
com.github.victools:jsonschema-generator.Root Cause: Spring AI 2.0.0-M4 depends on
jsonschema-generator:5.0.0(which uses Jackson 3.x /tools.jackson.core), while AgentScope usesjsonschema-generator:4.38.0(Jackson 2.x /com.fasterxml.jackson). When both coexist, Maven resolves to v5.0.0, causingNoSuchMethodErrorbecause theSchemaGenerator.generateSchema()return type changed fromcom.fasterxml.jackson.databind.node.ObjectNodetotools.jackson.databind.node.ObjectNode.Fix approach:
jsonschema-generatorfrom 4.38.0 → 5.0.0tools.jackson.core:jackson-databind:3.0.4as a dependencygenerateSchema().toString()→fromJson()tools.jackson.databind.JsonNodeChanges
agentscope-dependencies-bom/pom.xmlagentscope-core/pom.xmltools.jackson.core:jackson-databindagentscope-distribution/agentscope-all/pom.xmltools.jackson.core:jackson-databindJsonSchemaUtils.java.toString()+fromJson()instead of Jackson 2.xconvertValue()for schema generationToolSchemaModuleTest.javacom.fasterxml.jackson.databind.JsonNode→tools.jackson.databind.JsonNodeTest Plan
JsonSchemaUtilsTest— all 7 tests passToolSchemaModuleTest— all 8 tests passagentscope-coremodule compilation succeedsCloses #1271