Skip to content

SONARJAVA-7095 Implement JSON serialization for the common Spring context gathering model - #6283

Open
aurelien-coet-sonarsource wants to merge 1 commit into
ac/SONARJAVA-7095from
ac/SONARJAVA-7095-2
Open

aurelien-coet-sonarsource wants to merge 1 commit into
ac/SONARJAVA-7095from
ac/SONARJAVA-7095-2

Conversation

@aurelien-coet-sonarsource

@aurelien-coet-sonarsource aurelien-coet-sonarsource commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • JSON serialization:
    • Implemented SpringContextGatheringModelTypeAdapter to serialize and deserialize Spring context data by module and file
    • Added JSON adapter annotations to SpringContextGatheringModel, BeanDefinitionHolder.InputFileData, and InjectionPoint.InputFileData
  • Tests:
    • Added comprehensive unit tests in SpringContextGatheringModelTypeAdapterTest covering round-trips, missing properties, and empty modules

This will update automatically on new commits.

@aurelien-coet-sonarsource
aurelien-coet-sonarsource added this pull request to stack #6284 October 1, 2026 11:38
@aurelien-coet-sonarsource aurelien-coet-sonarsource changed the title Implement JSON serialization for the common Spring context gathering … SONARJAVA-7095 Implement JSON serialization for the common Spring context gathering model Oct 1, 2026
@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title SONARJAVA-7095 Implement JSON serialization for the common Spring context gathering model SONARJAVA-7113 Implement JSON serialization for the common Spring context gathering … Oct 1, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7095

@aurelien-coet-sonarsource aurelien-coet-sonarsource changed the title SONARJAVA-7113 Implement JSON serialization for the common Spring context gathering … SONARJAVA-7095 Implement JSON serialization for the common Spring context gathering model Oct 1, 2026
@aurelien-coet-sonarsource
aurelien-coet-sonarsource force-pushed the ac/SONARJAVA-7095-2 branch 2 times, most recently from 8408443 to 3cfac26 Compare October 1, 2026 12:30
@gitar-bot

gitar-bot Bot commented Oct 2, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk · Adds JSON serialization and deserialization for Spring context model data.

Implements JSON serialization for the Spring context gathering model with a custom SpringContextGatheringModelTypeAdapter to handle module and file-level context data. The @JsonAdapter bean round-trip issue under Gson's default null handling has been resolved, and comprehensive unit tests cover round-trips, missing properties, and empty modules. Ready to merge.

✅ 1 closed
✅ Bug: @JsonAdapter bean round-trip fails under Gson's default null handling

📄 java-frontend/src/main/java/org/sonar/java/model/springcontext/BeanDefinitionHolder.java:238 📄 java-frontend/src/main/java/org/sonar/java/serialization/SpringContextGatheringModelTypeAdapter.java:55-56
The new @JsonAdapter(BeanDefinitionHolderTypeAdapter.class) lets anyone call new Gson().toJson(bean) / fromJson(json, BeanDefinitionHolder.InputFileData.class) directly. The adapter's write relies on the caller having turned on serializeNulls. Today only SpringContextGatheringModelTypeAdapter.write does that (and possibly the cache helper's own writer). A default Gson writer has serializeNulls=false, so out.name(PROFILES).value((String) null) drops both the name and the value for every unconditional bean, and so does a null qualifier. read then throws missingProperty(PROFILES) because profilesRead stays false. That means the standalone round-trip this annotation advertises fails for the most common kind of bean (one with no @Profile). Fix: have BeanDefinitionHolderTypeAdapter.write save out.getSerializeNulls(), force it to true, and restore it in a finally, the same way the model adapter does. Alternatively, treat a missing profiles key as unconditional.

Review coverage

🧪 Functional validation 2 of 2 objectives covered

📋 Rules No rules evaluated

Cross-repo coverage 1 repository selected

Cross-repo inspection is incomplete. Unread code may contain additional impacts.

🤖 Auto-approval Not enabled · Set up

Implementation Status ✅ 2 of 2 objectives covered
✅ SONARJAVA-7095 - 2 of 2 objectives covered

This PR implements on-disk serialization and de-serialization for the Spring context gathering model via custom Gson type adapters and tests.

✅ 2 covered here
  • ✅ Implement on-disk serialization for the Spring context model
  • ✅ Implement on-disk de-serialization for the Spring context model
Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

sonarqube-next Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

This branch has not been deployed

No deployments
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.

1 participant