Repository navigation
refactor: replace QJson with nlohmann/json in OMSFileLoad - #8936
Conversation
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]>
📝 WalkthroughWalkthroughReplaced 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
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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. Comment |
There was a problem hiding this comment.
🧹 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_LIBRARIESto minimize transitive dependencies. Including it in this header means any code that includesOMSFileLoad.hwill transitively includenlohmann/json.hpp.Since
exportTableToJSON_is a private method, consider one of these alternatives to keep nlohmann_json out of the header:
- Return
voidand accept an output parameter (e.g.,nlohmann::json&)- Use a forward-declared wrapper type
- 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
📒 Files selected for processing (2)
src/openms/include/OpenMS/FORMAT/OMSFileLoad.hsrc/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]>
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
src/openms/include/OpenMS/FORMAT/OMSFileLoad.hsrc/openms/source/FORMAT/OMSFileLoad.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
- src/openms/include/OpenMS/FORMAT/OMSFileLoad.h
| 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; |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Does QJsonValue treat SQL NULL as empty string or JSON null?
💡 Result:
QJsonValue treats SQL NULL as JSON null.
Citations:
- 1: https://doc.qt.io/qt-6/qjsonvalue.html
- 2: https://doc.qt.io/qt-5/qjsonvalue.html
- 3: https://stackoverflow.com/questions/18058936/qt-qsqlquery-return-in-json
- 4: https://doc.qt.io/qt-5/qsqlquery.html
- 5: https://doc.qt.io/qt-6/sql-sqlstatements.html
- 6: https://stackoverflow.com/questions/3387747/qt-and-sqlite-cant-handle-null-values-or-im-doning-something-wrong
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.
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]>
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]>
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]>
Summary
std::map<QString, QString>tostd::map<String, String>dump(4)for indented output matching Qt's default formattingTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit