Comments (6)
I worked several hours on this issue but could not find an elegant solution that doesn't increase the code size significantly.
If it were a functionality used by many users, I would accept this penalty, but you are the first to notice this problem in 10 years.
I plan to implement the fix in ArduinoJson 7, which has looser code size constraints.
from arduinojson.
Anticipating the possible response that may come, in my project's API, I don't have direct access to the JsonDocument, so I can't use the capacity() memoryUsage() methods to try to workaround this issue.
from arduinojson.
Ok. I worked around it keeping a count of the JsonObject that were successfully added to the JsonArray and when it exits the loop (because the last addition failed due to memory), I compare the size()
of the JsonArray with that count. If they differ, then It means that although the addition failed, something was added nevertheless, so I have to delete the last item of the array (the partially added JsonObject).
from arduinojson.
Hi @gonzabrusco,
I guess I could add a special treatment for add()
so as to provide this "transactional guarantee", but I cannot do the same for set()
since the original value is lost.
Also, this "transactional guarantee" would be very limited since you'd not necessarily return to the state before the operation. For example, if add failed in the following program:
doc["config"]["wifi"].add(newAccessPointObject);
If doc
was initially:
{"config":{"url":"api.example.com"}}
After "reverting" the failing add()
, we would end up with:
{"config":{"url":"api.example.com","wifi":[]}}
It is probably okay, but definitely not the same as the original.
Moreover, because ArduinoJson 6's allocator is monotonic, we cannot recover the memory consumed by the removed object.
Best regards,
Benoit
from arduinojson.
Yes I understand what you are saying but I still think that what I propose would be the correct choice in this regard. If the add method fails, it should not leave "a partial copy" of a JSON.
In the example you provided, it "fails" because you are doing two things at a time (creating an array and then adding an item). I think in that case the user should use JsonDocument::createNestedArray() and check the return value before adding items. Or just leave the array empty (which is probably fine because the other end is probably expecting the array, empty or not).
from arduinojson.
Fair enough. I will stick to my workaround then. Thank you for taking the time to evaluate this issue.
Feel free to what you want with this issue report.
from arduinojson.
Related Issues (20)
- How do i create JSON array of objects using ArduinoJson library. HOT 1
- Identifying JsonVariant type of a deserialized document HOT 4
- Example code results in compiler error: no match for 'operator+=' HOT 3
- Passing JsonDocument by reference HOT 4
- In Memory Deserialization HOT 4
- v7 equivalent of validateJson HOT 2
- conversion from ‘ArduinoJson::V704HB42::detail::enable_if<true, ArduinoJson::V704HB42::JsonVariantConst>::type’ {aka ‘ArduinoJson::V704HB42::JsonVariantConst’} to ‘ArduinoJson::V704HB42::JsonDocument’ is ambiguous HOT 1
- Assertion `poolIndex < count_' failed HOT 1
- Maximum string length of 13 characters HOT 2
- V6 Documentation ArduinoJson PubSubClient with StreamUtils HOT 1
- deserialize file from LittleFS crash HOT 6
- Trying to compile a 2021 program HOT 2
- Bring back zero-copy mode in v7 HOT 6
- MQTT Publish destroying Json HOT 2
- Error compiling example code SimpleParser on Arduino Web Editor NodeMCU 0.9 HOT 1
- JSON output is truncated. HOT 1
- load an object into an absolute memory address, Cortex-M. HOT 4
- Cannot compile code that compiled last time it was used HOT 1
- There is a memory leak either in this library or in ESP32 LittleFS HOT 20
- Lint error ovl_no_viable_subscript has occured HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduinojson.