Skip to content

refactor(testcontainers): extract ObjectMapper to static field in tdg.Utils#96

Merged
dkasimovskiy merged 1 commit into
masterfrom
refactor/tdg-utils-static-objectmapper
Jun 11, 2026
Merged

refactor(testcontainers): extract ObjectMapper to static field in tdg.Utils#96
dkasimovskiy merged 1 commit into
masterfrom
refactor/tdg-utils-static-objectmapper

Conversation

@dkasimovskiy

Copy link
Copy Markdown
Contributor

Hoist the ObjectMapper instance used by the test helper
org.testcontainers.containers.tdg.Utils from a method-local variable to
a static final field.

ObjectMapper instances are thread-safe once configured, so the previous
new ObjectMapper() allocations in sendUsers(List<User>, TDGContainer<?>)
and getUsers(int, TDGContainer<?>) were unnecessary and duplicated.
Extracting the instance:

  • removes the per-call allocation and the duplicated new ObjectMapper()
    call sites;
  • keeps the mapper in a single, clearly named place (OBJECT_MAPPER),
    matching the UPPER_SNAKE_CASE convention for static final fields;
  • makes future configuration of the mapper (modules, features) a
    one-line change in a single spot instead of two.

This is a test-only refactor — Utils lives under src/test/java and is
not part of the published artifact, so there is no API or behavior change
for SDK consumers.

I haven't forgotten about:

  • Tests
  • Changelog
  • Documentation
    • JavaDoc was written
  • Commit messages comply with the guideline
  • Cleanup the code for review. See checklist

….Utils

ObjectMapper instances are thread-safe after configuration and can be
safely reused. Hoisting the instance to a static final field removes
the duplicated `new ObjectMapper()` allocations in sendUsers() and
getUsers() and avoids creating a fresh mapper (and re-reading its
configuration) on every call.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dkasimovskiy dkasimovskiy merged commit af2c663 into master Jun 11, 2026
12 of 16 checks passed
@dkasimovskiy dkasimovskiy deleted the refactor/tdg-utils-static-objectmapper branch June 11, 2026 13:14
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.

2 participants