Skip to content

Centralize ObjectMapper construction via JsonUtils.newObjectMapper()#1040

Merged
akshayrai merged 3 commits into
linkedin:masterfrom
akshayrai:jsonutils-new-object-mapper
Jun 29, 2026
Merged

Centralize ObjectMapper construction via JsonUtils.newObjectMapper()#1040
akshayrai merged 3 commits into
linkedin:masterfrom
akshayrai:jsonutils-new-object-mapper

Conversation

@akshayrai

Copy link
Copy Markdown
Collaborator

Summary

Centralizes Jackson ObjectMapper creation through a single factory, JsonUtils.newObjectMapper(), establishing a single source of truth for mapper configuration. Every ObjectMapper returned by the factory is preconfigured with FAIL_ON_UNKNOWN_PROPERTIES = false, preventing failures during rolling deployments, schema evolution, or cross-version communication when additional JSON fields are introduced.

Previously, each call site instantiated its own new ObjectMapper() and had to configure (or remember to configure) the appropriate defaults. By routing construction through a shared factory, future configuration changes—such as registering new modules or enabling additional feature flags—are applied consistently across the codebase without requiring updates to every caller.

Testing Done

PR checks

akshayrai and others added 2 commits June 29, 2026 16:12
… checkstyle-enforce

Adds a public static factory `JsonUtils.newObjectMapper()` that returns a fresh
ObjectMapper pre-configured with the codebase-wide Jackson defaults (currently:
FAIL_ON_UNKNOWN_PROPERTIES disabled), giving every Jackson consumer a single
source of truth for mapper construction so future default tweaks propagate
without each caller re-discovering the right config.
The private MAPPER in JsonUtils is rewired to call the factory and then layer
its existing Datastream mixIns on top, so toJson / fromJson behavior is
unchanged. Five main-source call sites are migrated to the factory
(KafkaDatastreamStatesResponse, DatastreamRestClientCli,
FileBasedPartitionThroughputProvider x2, AvroJson).
A Checkstyle RegexpSingleline rule "RawObjectMapperConstruction" fails the
build on any `new ObjectMapper(` outside JsonUtils.java (suppressed via
checkstyle/suppressions.xml), pointing contributors at the factory. Adds
TestJsonUtils covering non-null, FAIL_ON_UNKNOWN_PROPERTIES disabled,
unknown-property tolerance, and fresh-instance-per-call.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Group the Guava CaseFormat import with the other third-party com.* imports
(after com.fasterxml.*) so it precedes the com.linkedin.* import block, as
required by the ImportOrder checkstyle rule.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@dhananjay-sawner dhananjay-sawner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Place the org.testng.* imports before the com.fasterxml.* imports, matching
the checkstyle group order (java/javax, org, other, com.linkedin) with a
blank line separating the groups.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@dhananjay-sawner dhananjay-sawner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@akshayrai akshayrai merged commit b1efc94 into linkedin:master Jun 29, 2026
1 check passed
akshayrai added a commit that referenced this pull request Jul 1, 2026
Two parallel PRs (#1038 'Checkstyle class-design cleanup' and #1040
'Centralize ObjectMapper construction via JsonUtils.newObjectMapper()')
each independently added a private no-arg constructor to JsonUtils,
merging into master with two definitions of the same constructor.
This broke compilation of datastream-common with:
error: constructor JsonUtils() is already defined in class JsonUtils
Removed the duplicate, keeping the field declarations before the
single remaining private constructor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants