Skip to content

fix(P4): replace per-call ObjectMapper with Spring-managed bean - #73

Merged
lekhrocks merged 1 commit into
mainfrom
feature/p4-objectmapper-reuse
Sep 6, 2026
Merged

lekhrocks merged 1 commit into
mainfrom
feature/p4-objectmapper-reuse

Conversation

@lekhrocks

Copy link
Copy Markdown
Owner

Summary

Replaces per-call new ObjectMapper() instances with the Spring-managed bean across three classes.

Problem

AgentRegistrar, HeartbeatSender, and LlmClient each created new ObjectMapper() on every HTTP call. ObjectMapper is expensive to construct and thread-safe once configured — creating throwaway instances wastes CPU and ignores the application's configured Jackson modules (JavaTimeModule, etc.).

Fix

File Change
AgentRegistrar.java Inject ObjectMapper via constructor; use it for writeValueAsString and readTree
HeartbeatSender.java Inject ObjectMapper via constructor; use it for writeValueAsString
LlmClient.java Inject ObjectMapper via constructor instead of new ObjectMapper()

All three classes are @Components in a Spring Boot context — the auto-configured primary ObjectMapper bean (with JavaTimeModule registered) is injected automatically.

AgentRegistrar, HeartbeatSender, and LlmClient each created
new ObjectMapper() on every call. Inject the Spring-managed
ObjectMapper bean instead — thread-safe, properly configured
with JavaTimeModule, and reused across the application lifecycle.
@lekhrocks
lekhrocks merged commit dc250f0 into main Sep 6, 2026
19 checks passed
@lekhrocks
lekhrocks deleted the feature/p4-objectmapper-reuse branch September 6, 2026 06:37
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.

1 participant