Skip to content

refactor: replace QJson with nlohmann/json in OMSFileLoad - #8936

Merged
timosachsenberg merged 3 commits into
developfrom
remove-qt/pr1-json
Mar 18, 2026
Merged

timosachsenberg merged 3 commits into
developfrom
remove-qt/pr1-json

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace QJsonArray/QJsonObject/QJsonDocument with nlohmann::json in OMSFileLoad.h/.cpp
  • Change std::map<QString, QString> to std::map<String, String>
  • Use dump(4) for indented output matching Qt's default formatting
  • Part 1/7 of removing Qt6::Core from libOpenMS core library

Test plan

  • OMSFile_test passes
  • JSONExporter TOPP tests pass (output byte-identical to Qt)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Internal JSON export rewritten to use a standard JSON implementation and unified string handling for consistency.
    • Improved JSON construction and output formatting, and streamlined table export logic.
    • No changes to external behavior or user-visible data formats.

timosachsenberg and others added 2 commits March 18, 2026 13:27
Remove Qt JSON dependencies (QJsonArray, QJsonDocument, QJsonObject,
QString) from OMSFileLoad.h/.cpp and replace with nlohmann::ordered_json
to preserve insertion order. Use dump(2) for indented output matching
Qt's default behavior. Also eliminate remaining toQString() calls in
prepareQueryMetaInfo_ and prepareQueryAppliedProcessingStep_.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…trailing newline)

Replace nlohmann::ordered_json with nlohmann::json to match Qt's alphabetical
key sorting, change dump(2) to dump(4) for 4-space indentation matching
QJsonDocument::toJson() defaults, and append trailing '\n' to match Qt's output.
Add 'using json = nlohmann::json' type aliases for readability.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Replaced Qt JSON types and QString usage in OMSFileLoad with nlohmann::json and OpenMS::String. The exportTableToJSON_ function signature and return type changed; related members (subquery_score_, export_order_by_) and internal JSON construction were updated accordingly.

Changes

Cohort / File(s) Summary
JSON & String migration
src/openms/include/OpenMS/FORMAT/OMSFileLoad.h, src/openms/source/FORMAT/OMSFileLoad.cpp
Replaced Qt JSON types (QJsonArray, QJsonObject, QJsonDocument) with nlohmann::json. Changed exportTableToJSON_ signature and return type to use nlohmann::json and OpenMS::String. Updated subquery_score_ and export_order_by_ to use String. Adjusted internal SQL and JSON construction to OpenMS String and nlohmann::json APIs.

Poem

I hopped from Qt to json’s shore, 🐇
where nlohmann’s bytes now gently pour.
Strings aligned in tidy rows,
exports sparkle as code grows,
a happy hop — then back for more!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: replacing QJson (Qt JSON types) with nlohmann/json in the OMSFileLoad component. It matches the primary objective and file changes accurately.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch remove-qt/pr1-json
📝 Coding Plan
  • Generate coding plan for human review comments

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/openms/include/OpenMS/FORMAT/OMSFileLoad.h (1)

15-15: Including nlohmann/json.hpp in this public header exposes the dependency to downstream users.

According to learnings, nlohmann_json is intentionally kept as a PRIVATE dependency in OPENMS_DEP_PRIVATE_LIBRARIES to minimize transitive dependencies. Including it in this header means any code that includes OMSFileLoad.h will transitively include nlohmann/json.hpp.

Since exportTableToJSON_ is a private method, consider one of these alternatives to keep nlohmann_json out of the header:

  1. Return void and accept an output parameter (e.g., nlohmann::json&)
  2. Use a forward-declared wrapper type
  3. Move the return type to an opaque pointer/pimpl if feasible

If this exposure is intentional for Part 1/7 of the Qt removal refactor and will be addressed in subsequent PRs, this can be deferred.

Based on learnings: "nlohmann_json is intentionally kept as a PRIVATE dependency in OPENMS_DEP_PRIVATE_LIBRARIES."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/FORMAT/OMSFileLoad.h` at line 15, The public header
currently includes nlohmann/json.hpp which exposes that PRIVATE dependency;
remove the include from the header and change the private method
exportTableToJSON_ so it no longer returns or references nlohmann::json in the
header (e.g., make exportTableToJSON_ return void and accept an output parameter
such as std::ostream& or std::string&), then implement the JSON construction in
the .cpp where you can include nlohmann/json.hpp; alternatively you can move
exportTableToJSON_ implementation into the source and keep only an opaque
declaration in the header or introduce a small forward-declared wrapper type to
avoid leaking nlohmann types.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/openms/include/OpenMS/FORMAT/OMSFileLoad.h`:
- Line 15: The public header currently includes nlohmann/json.hpp which exposes
that PRIVATE dependency; remove the include from the header and change the
private method exportTableToJSON_ so it no longer returns or references
nlohmann::json in the header (e.g., make exportTableToJSON_ return void and
accept an output parameter such as std::ostream& or std::string&), then
implement the JSON construction in the .cpp where you can include
nlohmann/json.hpp; alternatively you can move exportTableToJSON_ implementation
into the source and keep only an opaque declaration in the header or introduce a
small forward-declared wrapper type to avoid leaking nlohmann types.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7c6aab9d-28c1-4838-b54f-4300796bd473

📥 Commits

Reviewing files that changed from the base of the PR and between 0bcae36 and 02fa606.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/FORMAT/OMSFileLoad.h
  • src/openms/source/FORMAT/OMSFileLoad.cpp

MSVC CI failed because nlohmann/json.hpp include path wasn't
available transitively from the header. Move exportTableToJSON_
from private method to file-local function, removing the need
for nlohmann/json in the header entirely.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/openms/source/FORMAT/OMSFileLoad.cpp`:
- Around line 1127-1131: In the SQLITE_NULL case inside the switch that
populates record from query (look for the case labeled SQLITE_NULL near the
other SQLITE_* cases using query.getColumnName(i) / query.getColumn(i)), stop
assigning an empty string and instead assign a JSON null value so database NULLs
become JSON nulls (e.g., use the appropriate QJsonValue null/nullptr
representation used elsewhere in the codebase); update that case to set
record[query.getColumnName(i)] to a JSON null.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a529d749-8e21-4eae-8382-bf26ec76e9ff

📥 Commits

Reviewing files that changed from the base of the PR and between 02fa606 and 57604f8.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/FORMAT/OMSFileLoad.h
  • src/openms/source/FORMAT/OMSFileLoad.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/openms/include/OpenMS/FORMAT/OMSFileLoad.h

Comment on lines +1127 to +1131
case SQLITE_INTEGER: record[query.getColumnName(i)] = query.getColumn(i).getInt64(); break;
case SQLITE_FLOAT: record[query.getColumnName(i)] = query.getColumn(i).getDouble(); break;
case SQLITE_BLOB: record[query.getColumnName(i)] = query.getColumn(i).getText(); break;
case SQLITE_NULL: record[query.getColumnName(i)] = ""; break;
case SQLITE3_TEXT: record[query.getColumnName(i)] = query.getColumn(i).getText(); break;

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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Does QJsonValue treat SQL NULL as empty string or JSON null?

💡 Result:

QJsonValue treats SQL NULL as JSON null.

Citations:


Fix SQLITE_NULL handling to use JSON null instead of empty string.

Line 1130 converts SQL NULL to empty string "", but QJsonValue treats SQL NULL as JSON null. These are semantically different in JSON output. To match Qt's behavior (as claimed in the PR), use:

case SQLITE_NULL: record[query.getColumnName(i)] = nullptr; break;

The current code will produce incorrect output where NULL database values are converted to empty strings instead of JSON nulls.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/FORMAT/OMSFileLoad.cpp` around lines 1127 - 1131, In the
SQLITE_NULL case inside the switch that populates record from query (look for
the case labeled SQLITE_NULL near the other SQLITE_* cases using
query.getColumnName(i) / query.getColumn(i)), stop assigning an empty string and
instead assign a JSON null value so database NULLs become JSON nulls (e.g., use
the appropriate QJsonValue null/nullptr representation used elsewhere in the
codebase); update that case to set record[query.getColumnName(i)] to a JSON
null.

@timosachsenberg
timosachsenberg merged commit 355bef5 into develop Mar 18, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the remove-qt/pr1-json branch March 18, 2026 14:48
github-actions Bot pushed a commit that referenced this pull request Mar 19, 2026
PR #8936 (refactor: replace QJson with nlohmann/json in OMSFileLoad)
was merged on 2026-03-18, completing all 5 steps of Task 1 in the
remove-Qt6::Core-from-libOpenMS implementation plan.

Mark Steps 1-5 with [x] to reflect the merged implementation.

Co-authored-by: Copilot <[email protected]>
github-actions Bot pushed a commit that referenced this pull request Mar 20, 2026
Document the incremental Qt removal from libOpenMS core library:
- QDateTime/QDate/QSysInfo/QLocale replaced by std::chrono (#8937)
- QDir/QFile/QFileInfo replaced by std::filesystem (#8938)
- QProcess/QObject replaced by boost::process (#8939)
- QJsonDocument/QJsonObject replaced by nlohmann/json (#8936)

These changes landed after the 2026-03-19 changelog sync and represent
significant steps toward making Qt6 optional for the core library.

Co-authored-by: Copilot <[email protected]>
timosachsenberg added a commit that referenced this pull request Mar 20, 2026
Document the incremental Qt removal from libOpenMS core library:
- QDateTime/QDate/QSysInfo/QLocale replaced by std::chrono (#8937)
- QDir/QFile/QFileInfo replaced by std::filesystem (#8938)
- QProcess/QObject replaced by boost::process (#8939)
- QJsonDocument/QJsonObject replaced by nlohmann/json (#8936)

These changes landed after the 2026-03-19 changelog sync and represent
significant steps toward making Qt6 optional for the core library.

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Timo Sachsenberg <[email protected]>
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