chore: Add @JsonCreator to McpError#768
chore: Add @JsonCreator to McpError#768He-Pin wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
Signed-off-by: He-Pin <hepin1989@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds Jackson deserialization support to the McpError class by adding the @JsonCreator annotation to its constructor. This enables McpError instances to be properly deserialized from JSON, which is necessary for error handling in MCP protocol communication where McpError objects are serialized and sent over the wire.
Changes:
- Added
@JsonCreatorannotation to theMcpErrorconstructor - Added a Javadoc comment explaining the purpose of the annotation
- Imported
com.fasterxml.jackson.annotation.JsonCreator
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * Add @JsonCreator to make sure Jackson can deserialize it properly. | ||
| */ | ||
| @JsonCreator | ||
| public McpError(JSONRPCError jsonRpcError) { |
There was a problem hiding this comment.
When using @JsonCreator with a single-parameter constructor, it's recommended to explicitly annotate the constructor parameter with @JsonProperty to ensure reliable deserialization across different Jackson configurations. While the current code may work due to the -parameters compiler flag, adding @JsonProperty("jsonRpcError") to the constructor parameter would make the deserialization contract explicit and more robust.
This follows the pattern seen throughout the codebase where all record constructors explicitly use @JsonProperty annotations on their parameters (e.g., JSONRPCError in McpSchema.java:306-308).
Motivation and Context
Support deserialization McpError
How Has This Been Tested?
Use this in production
Breaking Changes
Types of changes
Checklist
Additional context