Skip to content

Conversation

@nknize
Copy link

@nknize nknize commented Jan 16, 2026

Motivation and Context

Applications using the MCP Java SDK with JPMS (Java Platform Module System) currently require --add-opens JVM flags because the Jackson ObjectMapper uses setAccessible() to access record constructors. This breaks module encapsulation and prevents full JPMS adoption.

This change configures the ObjectMapper to:

  1. Disable CAN_OVERRIDE_ACCESS_MODIFIERS to prevent setAccessible() calls
  2. Use ParameterNamesModule to discover constructor parameter names from bytecode

The SDK already compiles with -parameters, so no additional build configuration is needed.

How Has This Been Tested?

  • Added JpmsCompatibilityTests that verify record deserialization works without reflection
  • Tested with simple records, records with maps/lists, and nested records
  • Verified CAN_OVERRIDE_ACCESS_MODIFIERS is disabled via configuration test
  • All existing tests pass

Breaking Changes

None. This is a transparent configuration change. Applications that previously worked will continue to work, and applications that required --add-opens flags can now remove them.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Resolves #753

The ParameterNamesModule dependency is already transitively available via Jackson, but is now explicitly declared in pom.xml for clarity.

@nknize nknize force-pushed the feature/jpms-compatibility branch from 3e48ba9 to d93ba3d Compare January 26, 2026 05:00
Configure ObjectMapper with JPMS-compatible settings:
- Disable CAN_OVERRIDE_ACCESS_MODIFIERS to prevent setAccessible() calls
- Add ParameterNamesModule to discover constructor parameter names from
  bytecode instead of reflection

This allows applications using the MCP SDK to operate without
`--add-opens` JVM flags, enabling full JPMS module encapsulation.

The SDK already compiles with `-parameters` flag, which is required
for ParameterNamesModule to function.

Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
@nknize nknize force-pushed the feature/jpms-compatibility branch from d93ba3d to ee6444c Compare January 27, 2026 00:42
@nknize
Copy link
Author

nknize commented Jan 27, 2026

Rebased to Jackson 2 due to the recent Jackson 3 merge. Some projects still have transitive dependencies on Jackson 2 and can't rely on a Jackson 3 migration. This retains JPMS support for Jackson 2.

@nknize nknize changed the title Add JPMS compatibility to Jackson JSON mapper by configuring ObjectMapper to work without --add-opens JVM flags. Add JPMS compatibility to Jackson JSON 2 mapper by configuring ObjectMapper to work without --add-opens JVM flags. Jan 27, 2026
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.

Add JPMS compatibility to Jackson JSON mapper

1 participant