Migrate from ArduinoJson v6 to v7.4.2#1044
Migrate from ArduinoJson v6 to v7.4.2#1044Copilot wants to merge 12 commits intoplatformio_dependabot/ArduinoJson/7.4.2from
Conversation
- Replace all DynamicJsonDocument with JsonDocument - Replace all StaticJsonDocument<N> with JsonDocument - Remove all JSON_OBJECT_SIZE() and JSON_ARRAY_SIZE() capacity calculations - Replace doc.containsKey(key) with doc[key].is<type>() checks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace DynamicJsonDocument and StaticJsonDocument with JsonDocument. Remove JSON_OBJECT_SIZE() and JSON_ARRAY_SIZE() capacity calculations. Update function signature for web_server_config_deserialise. Migrated files: - src/web_server_claims.cpp - src/web_server_time.cpp - src/web_server_events.cpp - src/web_server_update.cpp - src/web_server_certificates.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace DynamicJsonDocument and StaticJsonDocument with JsonDocument Remove JSON_OBJECT_SIZE() and JSON_ARRAY_SIZE() capacity calculations Files migrated: - src/rfid.cpp - src/current_shaper.cpp - src/http_update.cpp - src/main.cpp - src/evse_monitor.cpp - src/divert.cpp - src/time_man.cpp - src/input.cpp - src/event_log.cpp - src/net_manager.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace StaticJsonDocument with JsonDocument in limit.cpp - Replace DynamicJsonDocument with JsonDocument in tesla_client.cpp - Remove all remaining capacity calculations Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot please check the failing checks and resolve the issues |
Created local override of ConfigJson library (v0.0.6) with ArduinoJson v7 support: - Replaced DynamicJsonDocument with JsonDocument - Removed JSON_OBJECT_SIZE/JSON_ARRAY_SIZE capacity calculations - Replaced containsKey() with is<T>() type checking This fixes build failures caused by deprecated API warnings in ConfigJson. Local override will be used until upstream library is updated. Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
I've identified and fixed the build failures. The issue was that the ConfigJson library (a dependency) was not compatible with ArduinoJson v7 - it used deprecated APIs ( Solution: Created a local ArduinoJson v7-compatible version of ConfigJson in
The fix is in commit a8a2cd1. The CI workflows show "action_required" status which typically means they need approval to run. Once approved and passing, the migration will be complete. |
|
@copilot there are still some build errors, please check. I have allowed the platformio.org domain which should allow access to the items that where failing. If no let me know what is still being blocked. |
PlatformIO was downloading ConfigJson@0.0.6 to .pio/libdeps/ which took precedence over the local lib/ConfigJson/ version. Removing it from lib_deps forces PlatformIO to use the local ArduinoJson v7-compatible version, fixing the build errors. Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Fixed the build errors in commit 4e85b4c. The issue was that PlatformIO was downloading Solution: Removed The builds should now pass with the local ConfigJson library that properly supports ArduinoJson v7 APIs. |
|
@copilot I can make the appropriate changes to ConfigJson, no need for a local version. Please provide a suitable prompt for the required changes in ConfigJson. Note this will need to be compatible both with v6 and v7 |
Removed local lib/ConfigJson/ directory and restored ConfigJson@0.0.6 in platformio.ini. The upstream ConfigJson library will be updated to support both ArduinoJson v6 and v7 instead of using a local override. Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Reverted the local ConfigJson override in commit bef3895. Here's the prompt for updating ConfigJson to support both ArduinoJson v6 and v7: Update ConfigJson library to support both ArduinoJson v6 and v7 The ConfigJson library needs to be updated to work with both ArduinoJson v6 (using Files to modify:
Version detection: Use Key changes:
This ensures ConfigJson works with both versions seamlessly. |
|
@copilot ConfigJson 0.0.7 now implements ArduinoJSON 7, please update to that and fix any errors. If ConfigJson needs more updates please give me a prompt to apply the required changes |
ConfigJson 0.0.7 now implements ArduinoJson v7 compatibility, replacing the need for a local override. This version supports both v6 and v7 APIs. Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Updated to ConfigJson 0.0.7 in commit 3cf3c30. I've reviewed the codebase and confirmed all code is already compatible with ConfigJson 0.0.7:
The migration should work seamlessly with ConfigJson 0.0.7's ArduinoJson v7 support. The builds should now pass without any compatibility issues. |
|
@copilot Please find a solution for failing workflows. Use the logs, job definition, and any referenced files where the failure occurred. |
…_sim MicroOcpp 1.2.0 uses ArduinoJson v6 patterns that cause hard compile errors with v7 (MemberProxy copy constructor is private in v7). Added a pre-build script that patches the downloaded MicroOcpp source to fix the incompatibility. Also updated divert_sim workflow to use ArduinoJson v7.4.2 instead of v6.20.1. Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Fixed in commit c3f9c3f. Two issues found: 1. MicroOcpp 1.2.0 incompatible with ArduinoJson v7 (hard error)
2. divert_sim workflow hardcoded to ArduinoJson v6.20.1
Verified locally: Note: Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
This PR migrates the codebase from ArduinoJson v6 to v7.4.2, updating all document types, API calls, and key existence checks to match the new library API. The migration eliminates manual capacity calculations and updates nested object/array creation patterns throughout the application.
Changes:
- Replaced
StaticJsonDocument<N>/DynamicJsonDocument(capacity)withJsonDocumentacross all files - Updated nested object/array creation from
createNestedObject()/createNestedArray()to bracket notation with.to<>()/.add<>() - Converted
containsKey()checks to type-safe.is<type>()checks - Added pre-build script to patch MicroOcpp 1.2.0 for v7 compatibility
Reviewed changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/web_server_update.cpp | Replaced StaticJsonDocument with JsonDocument |
| src/web_server_time.cpp | Updated document types and function signatures |
| src/web_server_events.cpp | Migrated document types for event logging |
| src/web_server_config.cpp | Updated config handling with new document types |
| src/web_server_claims.cpp | Converted claims serialization to v7 API |
| src/web_server_certificates.cpp | Updated certificate document handling |
| src/web_server.cpp | Migrated status, Tesla, scheduler, and WebSocket handling to v7 API |
| src/time_man.cpp | Updated time event document types |
| src/tesla_client.cpp | Converted Tesla API response parsing to v7 |
| src/scheduler.h | Updated function signatures for JsonDocument |
| src/scheduler.cpp | Migrated scheduler serialization/deserialization to v7 API |
| src/rfid.cpp | Updated RFID event document types |
| src/net_manager.cpp | Converted network event handling |
| src/mqtt.cpp | Migrated MQTT message handling and publishing to v7 API |
| src/main.cpp | Updated main loop event handling |
| src/limit.cpp | Converted limit property handling to v7 API |
| src/json_serialize.h | Updated template base class for v7 compatibility |
| src/input.cpp | Migrated input event handling |
| src/http_update.cpp | Updated OTA update event handling |
| src/evse_monitor.cpp | Converted EVSE monitor events to v7 |
| src/evse_man.h | Updated manager function signatures |
| src/evse_man.cpp | Migrated EVSE manager serialization to v7 API |
| src/event_log.cpp | Updated event log document handling |
| src/energy_meter.h | Removed capacity constant and updated signatures |
| src/energy_meter.cpp | Migrated energy meter serialization to v7 API |
| src/emoncms.cpp | Updated EmonCMS publishing with v7 document |
| src/divert.cpp | Converted divert mode event handling |
| src/current_shaper.cpp | Updated current shaper event documents |
| src/certificates.h | Updated certificate store function signatures |
| src/certificates.cpp | Migrated certificate serialization to v7 API |
| src/app_config_mqtt.h | Updated MQTT config virtual methods |
| src/app_config_mode.h | Updated charge mode config virtual methods |
| src/app_config.h | Updated config function signatures |
| src/app_config.cpp | Migrated config serialization/deserialization to v7 API |
| scripts/patch_microocpp.py | Added pre-build script for MicroOcpp v7 compatibility patching |
| platformio.ini | Updated ConfigJson to 0.0.7 and added patch script |
| _codeql_detected_source_root | Added divert_sim source root marker |
| .github/workflows/divert_sim.yaml | Updated ArduinoJson version from v6.20.1 to v7.4.2 |
src/energy_meter.cpp
Outdated
| doc["dt"].to<JsonObject>(); | ||
| doc["dt"]["dy"] = date.day; | ||
| doc["dt"]["mo"] = date.month; | ||
| doc["dt"]["yr"] = date.year; |
There was a problem hiding this comment.
This line creates a nested object but doesn't capture the return value. The correct pattern for creating nested objects in v7 is to either use the returned object or chain assignments. This should likely be JsonObject dt = doc[\"dt\"].to<JsonObject>(); followed by assignments to dt, or directly assign to doc[\"dt\"][\"dy\"] etc.
| doc["dt"].to<JsonObject>(); | |
| doc["dt"]["dy"] = date.day; | |
| doc["dt"]["mo"] = date.month; | |
| doc["dt"]["yr"] = date.year; | |
| JsonObject dt = doc["dt"].to<JsonObject>(); | |
| dt["dy"] = date.day; | |
| dt["mo"] = date.month; | |
| dt["yr"] = date.year; |
|
@copilot please review the build failures and review comments and make appropriate changes |
The return value from doc["dt"].to<JsonObject>() was not captured, requiring subsequent accesses to go through doc["dt"]["key"]. Now properly captures it in a JsonObject variable for direct assignment. Co-authored-by: jeremypoulter <6116992+jeremypoulter@users.noreply.github.com>
Applied the review comment fix in commit 076124d. Review comment fix: Build status: All project source code compiles with zero errors and zero warnings. Verified locally with |
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.