[BUG] new ObjectMapper() per MCP request (two sites)
- Dominant language
- Java
- Stars
- 8.8k
- Forks
- 3.1k
- Avg merge
- 7d 1h
- Merged PRs (30d)
- 85
Description
## Description
`ObjectMapper` construction is expensive (builds TypeFactory/serializers/mixins) and is constructed per request. The project already has `org.apache.shenyu.common.utils.JsonUtils.MAPPER`.
## Location
```
shenyu-plugin-mcp-server/.../McpServerPlugin.java:710 (new ObjectMapper().writeValueAsString(errorBody))
shenyu-plugin-mcp-server/.../transport/MessageHandlingResult.java:93 (new ObjectMapper().writeValueAsString(responseBody))
```
## Impact
Per-MCP-request ObjectMapper allocation on top of the serialization itself.
## Suggested fix
Reuse a static `ObjectMapper` (or `JsonUtils`). Line 710 also uses `errorResponse.getBytes()` (default charset) — use `StandardCharsets.UTF_8`.
## Related existing issue(s)
None
_Identified during the 2026-08-02 audit; full list in [`docs/issue-candidates-2026-08-02.md`](docs/issue-candidates-2026-08-02.md)._
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at McpServerPlugin.java:710 and transport/MessageHandlingResult.java:93, then inspect org.apache.shenyu.common.utils.JsonUtils.MAPPER. Replace the per-request ObjectMapper use with the existing shared mapper and address the response encoding at the plugin location; done means both sites avoid per-request construction and preserve UTF-8 output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100