Skip to content

Refactor ObjectMapper configuration for Elasticsearch#337

Merged
tuplle merged 2 commits intorelease/6.4.2from
NAE-2136_fix_object_mapper
Aug 19, 2025
Merged

Refactor ObjectMapper configuration for Elasticsearch#337
tuplle merged 2 commits intorelease/6.4.2from
NAE-2136_fix_object_mapper

Conversation

@renczesstefan
Copy link
Member

@renczesstefan renczesstefan commented Aug 19, 2025

Description

Moved the ObjectMapper configuration from ElasticsearchConfiguration to ElasticIndexService, because its quilified configuration overwrote the base ObjectMapper bean configuration. This improves cohesion by localizing the configuration closer to its usage. Removed unused bean, reducing complexity in the configuration class.

Additional fix to NAE-2136

Dependencies

No new dependencies were introduced

Third party dependencies

No new dependencies were introduced.

Blocking Pull requests

There are no dependencies on other PR.

How Has Been This Tested?

Manually and with unit tests.

Test Configuration

Name Tested on
OS macOS Sequoia 15.3.1
Runtime Java 21
Dependency Manager Maven 3.9.9n
Framework version Spring Boot 3.2.5
Run parameters
Other configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes have been checked, personally or remotely, with @Retoocs
  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved all conflicts with the target branch of the PR
  • I have updated and synced my code with the target branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes:
    • Lint test
    • Unit tests
    • Integration tests
  • I have checked my contribution with code analysis tools:
  • I have made corresponding changes to the documentation:
    • Developer documentation
    • User Guides
    • Migration Guides

Summary by CodeRabbit

  • Bug Fixes
    • Ensures consistent, human-readable date/time formatting for items indexed and shown in search results, preventing raw timestamps from appearing.
  • Refactor
    • Consolidated date/time serialization configuration into the search indexing component to simplify behavior and reduce misconfiguration risk.

Moved the ObjectMapper configuration from ElasticsearchConfiguration to ElasticIndexService. This improves cohesion by localizing the configuration closer to its usage. Removed unused bean, reducing complexity in the configuration class.
@coderabbitai
Copy link

coderabbitai bot commented Aug 19, 2025

Walkthrough

Removes the custom ObjectMapper bean from ElasticsearchConfiguration and moves Jackson JavaTime configuration into ElasticIndexService, which now creates and configures its own ObjectMapper with LocalDateTime serializers/deserializers. ElasticIndexService no longer receives an injected ObjectMapper; other Elasticsearch beans remain unchanged.

Changes

Cohort / File(s) Summary
Elasticsearch configuration cleanup
src/main/java/com/netgrif/application/engine/configuration/ElasticsearchConfiguration.java
Removed the elasticCaseObjectMapper bean (configureMapper()); imports adjusted as needed; other Elasticsearch beans unchanged.
ElasticIndexService mapper internalization
src/main/java/com/netgrif/application/engine/elastic/service/ElasticIndexService.java
Added private configureMapper() and internal ObjectMapper initialization registering JavaTimeModule with LocalDateTime serializer/deserializer and disabling WRITE_DATES_AS_TIMESTAMPS. Removed constructor ObjectMapper injection/@Qualifier and updated constructor to initialize mapper internally.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as ApplicationContext
  participant EIS as ElasticIndexService
  participant ES as ElasticsearchRestTemplate
  note over C: Bean initialization
  C->>EIS: create()
  activate EIS
  EIS->>EIS: new ObjectMapper()
  EIS->>EIS: configureMapper()\\n(register JavaTimeModule,\\nLocalDateTime serializer/deserializer,\\ndisable timestamps)
  deactivate EIS

  note over EIS,ES: Indexing/search operations use internal mapper
  EIS->>EIS: serialize/deserialize LocalDateTime
  EIS->>ES: perform ES operations
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between cb8cd88 and 43738ec.

📒 Files selected for processing (1)
  • src/main/java/com/netgrif/application/engine/configuration/ElasticsearchConfiguration.java (0 hunks)
💤 Files with no reviewable changes (1)
  • src/main/java/com/netgrif/application/engine/configuration/ElasticsearchConfiguration.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Test
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch NAE-2136_fix_object_mapper

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Retoocs
Retoocs previously approved these changes Aug 19, 2025
tuplle
tuplle previously approved these changes Aug 19, 2025
Removed unnecessary imports and unused dependencies from ElasticsearchConfiguration. This simplifies the code, improves readability, and ensures maintainability by decluttering the file.
@renczesstefan renczesstefan dismissed stale reviews from tuplle and Retoocs via 43738ec August 19, 2025 12:11
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/main/java/com/netgrif/application/engine/configuration/ElasticsearchConfiguration.java (1)

3-3: Clean up unused imports introduced by the refactor

These imports are not used anymore in this file and can be safely removed.

-import com.fasterxml.jackson.annotation.JsonInclude;
- import org.springframework.beans.factory.annotation.Qualifier;
- import org.springframework.core.annotation.Order;

Also applies to: 21-21, 25-25

src/main/java/com/netgrif/application/engine/elastic/service/ElasticIndexService.java (2)

108-110: Minor: consider reusing this ObjectMapper where feasible

ObjectMapper is thread-safe after configuration. Keeping a single instance per singleton service is fine. If you want to avoid extra instantiation elsewhere, you could reuse this mapper in parseAnalysisSettings() instead of creating a new one (not critical).


661-667: Consider excluding nulls from ES documents for leaner payloads

If the previous configuration (via the removed bean) excluded nulls, add it back here to preserve behavior and reduce index size. Safe for ES indexing and typically desired.

Apply:

+import com.fasterxml.jackson.annotation.JsonInclude;
@@
 private void configureMapper() {
     JavaTimeModule javaTimeModule = new JavaTimeModule();
     javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeJsonSerializer());
     javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeJsonDeserializer());
     objectMapper.registerModule(javaTimeModule);
     objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+    objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a45fb9e and cb8cd88.

📒 Files selected for processing (2)
  • src/main/java/com/netgrif/application/engine/configuration/ElasticsearchConfiguration.java (2 hunks)
  • src/main/java/com/netgrif/application/engine/elastic/service/ElasticIndexService.java (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/java/com/netgrif/application/engine/configuration/ElasticsearchConfiguration.java (1)
src/main/java/com/netgrif/application/engine/auth/domain/LoggedUser.java (1)
  • JsonInclude (16-137)
src/main/java/com/netgrif/application/engine/elastic/service/ElasticIndexService.java (2)
src/main/java/com/netgrif/application/engine/elastic/serializer/LocalDateTimeJsonDeserializer.java (1)
  • LocalDateTimeJsonDeserializer (13-29)
src/main/java/com/netgrif/application/engine/elastic/serializer/LocalDateTimeJsonSerializer.java (1)
  • LocalDateTimeJsonSerializer (11-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: task-list-completed
  • GitHub Check: Build
🔇 Additional comments (2)
src/main/java/com/netgrif/application/engine/elastic/service/ElasticIndexService.java (2)

5-7: LGTM: localized Jackson configuration for ES payloads

Moving the JavaTimeModule and custom LocalDateTime (de)serializers close to where JSON is produced for Elasticsearch is sensible. Keeps ES-specific JSON concerns isolated from the rest of the app.

Also applies to: 12-13


96-96: Verify DI wiring after removing ObjectMapper from ElasticIndexService constructor

Dropping the ObjectMapper from this constructor tightens its API surface. The automated scan returned no hits for:

  • @Qualifier("elasticCaseObjectMapper") or @Qualifier("configureMapper")
  • Calls to ElasticsearchConfiguration.configureMapper(...)
  • Manual instantiations via new ElasticIndexService(...)
  • Any @Autowired or field injections of ObjectMapper expecting an ES-specific mapper

Please manually confirm that:

  • No Spring bean definitions (JavaConfig or XML) still reference the old constructor signature
  • Test classes or factory methods aren’t instantiating ElasticIndexService directly with the removed parameter
  • Any other modules or components don’t rely on the ES-tailored ObjectMapper being injected here

@tuplle tuplle merged commit 62355cb into release/6.4.2 Aug 19, 2025
5 of 7 checks passed
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