Skip to content

Fix deprecated API usage patterns in Spring Boot tutorials #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 21, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 20, 2025

Problem

The Spring Boot tutorials contained deprecated API usage patterns that could lead to performance issues and inconsistent behavior:

  1. Batch modules: Creating new ObjectMapper instances repeatedly in method calls
  2. MongoDB module: Using deprecated TextIndexDefinitionBuilder constructor

Changes Made

Fixed ObjectMapper Anti-pattern

Before:

private JsonItemReader<User> reader() throws MalformedURLException {
    JacksonJsonObjectReader<User> jsonObjectReader = new JacksonJsonObjectReader<>(User.class);
    jsonObjectReader.setMapper(new ObjectMapper()); // ❌ Creating new instance every time
    return new JsonItemReaderBuilder<User>()...
}

After:

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); // ✅ Single static instance

private JsonItemReader<User> reader() throws MalformedURLException {
    JacksonJsonObjectReader<User> jsonObjectReader = new JacksonJsonObjectReader<>(User.class);
    jsonObjectReader.setMapper(OBJECT_MAPPER); // ✅ Reusing static instance
    return new JsonItemReaderBuilder<User>()...
}

Fixed TextIndexDefinitionBuilder Anti-pattern

Before:

import org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder;
// ...
new TextIndexDefinitionBuilder().onFields("name", "publisher").build() // ❌ Deprecated constructor

After:

import org.springframework.data.mongodb.core.index.TextIndexDefinition;
// ...
TextIndexDefinition.builder().onFields("name", "publisher").build() // ✅ Modern static factory method

Modules Updated

  • batch-rest-repository: Fixed ObjectMapper instantiation in JSON reader
  • batch-skip-step: Fixed ObjectMapper instantiation in JSON reader
  • data-mongodb-full-text-search: Fixed TextIndexDefinitionBuilder usage in both test and implementation files

Verification

  • ✅ All affected tests pass with new implementations
  • ✅ No functionality regressions introduced
  • ✅ Performance improved by eliminating repeated object instantiation
  • ✅ Code now follows modern Spring Boot and Spring Data MongoDB best practices

This change improves code quality by eliminating deprecated patterns, reducing memory allocation overhead, and ensuring consistent behavior across the application.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: rashidi <380073+rashidi@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Identify deprecated api usages in the project Fix deprecated ObjectMapper instantiation pattern in batch modules Aug 20, 2025
@Copilot Copilot AI requested a review from rashidi August 20, 2025 04:40
@rashidi
Copy link
Owner

rashidi commented Aug 20, 2025

@copilot Look into data-mongodb-full-text-search/src/test/java/zin/rashidi/boot/data/mongodb/character/CharacterRepositoryTests.java which has deprecated API usage.

…B module

Co-authored-by: rashidi <380073+rashidi@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 20, 2025

@copilot Look into data-mongodb-full-text-search/src/test/java/zin/rashidi/boot/data/mongodb/character/CharacterRepositoryTests.java which has deprecated API usage.

Fixed the deprecated TextIndexDefinitionBuilder constructor usage in the MongoDB module. Replaced new TextIndexDefinitionBuilder() with the modern TextIndexDefinition.builder() static factory method in both the test and implementation files. All tests pass with the updated implementation. (048fd77)

@Copilot Copilot AI changed the title Fix deprecated ObjectMapper instantiation pattern in batch modules Fix deprecated API usage patterns in Spring Boot tutorials Aug 20, 2025
Copilot finished work on behalf of rashidi August 20, 2025 14:30
Copy link

@rashidi rashidi marked this pull request as ready for review August 21, 2025 00:32
@rashidi rashidi merged commit eeb91b1 into master Aug 21, 2025
8 checks passed
@rashidi rashidi deleted the copilot/fix-58fe859e-1174-4e40-9e8d-fe79296ab22f branch August 21, 2025 00:33
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