Centralize ObjectMapper construction via JsonUtils.newObjectMapper()#1040
Merged
akshayrai merged 3 commits intoJun 29, 2026
Merged
Conversation
… 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>
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>
harshOSS
approved these changes
Jun 29, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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