Skip to content

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

Merged
aurelien-coet-sonarsource merged 1 commit into
ac/SONARJAVA-7095from
ac/SONARJAVA-7095-2
Oct 8, 2026
Merged

aurelien-coet-sonarsource merged 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

  • New type adapters:
    • Added SpringContextGatheringModelTypeAdapter for serializing and deserializing Spring context gathering models
    • Added corresponding test suite in SpringContextGatheringModelTypeAdapterTest

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
@datadog-sonarsource

This comment has been minimized.

@asya-vorobeva asya-vorobeva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯

@gitar-bot

gitar-bot Bot commented Oct 8, 2026 •

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

🟡 Medium risk · Serializing Spring context data across modules and files could omit bean or package metadata, producing incomplete context for subsequent analysis.

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 0 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 ◻️ 0 of 2 objectives covered
◻️ SONARJAVA-7095 - 0 of 2 objectives covered

This PR does not implement any of the stated objectives for Spring context model serialization or deserialization.

Other objectives on this issue, possibly covered elsewhere:

  • ◻️ 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 8, 2026

Copy link
Copy Markdown
Contributor

@aurelien-coet-sonarsource
aurelien-coet-sonarsource merged commit eaba13a into master Oct 8, 2026
18 checks passed
@aurelien-coet-sonarsource
aurelien-coet-sonarsource deleted the ac/SONARJAVA-7095-2 branch October 8, 2026 11:57
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