Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add JPMS compatibility to Jackson JSON mapper #753

Open
@nknize

Description

Expected Behavior

Applications using the MCP Java SDK should work with JPMS (Java Platform Module System) without requiring --add-opens JVM flags. Record deserialization should work through public constructors and parameter name discovery rather than reflective access.

 // Should work without --add-opens flags
 McpJsonMapper mapper = new JacksonMcpJsonMapperSupplier().get();
 MyRecord record = mapper.readValue(json, MyRecord.class);

Current Behavior

The JacksonMcpJsonMapperSupplier creates a plain ObjectMapper that uses reflection to access record constructors. This requires --add-opens JVM flags like:

 --add-opens java.base/java.lang.reflect=ALL-UNNAMED

Without these flags, deserialization of Java records fails with InaccessibleObjectException.

Context

We're integrating the MCP SDK into a JPMS-modularized application and cannot use --add-opens flags as they break module encapsulation.

The fix is straightforward:

  1. Disable MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS to prevent setAccessible() calls
  2. Add ParameterNamesModule to discover constructor parameters from bytecode

The SDK already compiles with -parameters, so ParameterNamesModule will work without additional configuration.

Workaround: We currently maintain a custom MCP client with JPMS-compatible Jackson configuration, but would prefer to use the upstream SDK directly.

I have a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /