Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #1807
Closed
Open
Issue created Oct 03, 2022 by Administrator@rootContributor

String copy policy behavior?

Created by: samvik

Describe the issue
First of all thanks for a grate library.

We are finding that it is a bit unintuitive and error prone when it comes to string handling. More specifically where const char* is not copied but char* is. Since we try to keep as much as possible const and this has nothing to do with lifetime we often end up having to const_cast pointers in order to force arduinojson to copy the string (easy to forget and leads to strange runtime errors). We have mitigated the issue a bit by implementing custom converters for our string classes (mainly etl::string and etl::string_view), but this has it's limitations see question 2 below.

So to my questions.

1. Any way to disable zerocopy entirely for a single document or for the entire library? Or is it possible to use another setter that will always copy?

2. The custom converters only seems to work on the value and not the keys, is this by design? See example below.

etl::string_view str = ...;
doc[str] = 1234; // Does not compile
doc["name"] = str; // Compiles and work

3. Is there a better way of handling/controlling the behavior? In other words have we misunderstood how to use arduinojson efficiently?

Thanks /Björn

Troubleshooter report

  1. The issue happens at run time
  2. The issue concerns serialization
  3. Output contains garbage
  4. serializeJson() produces garbage
  5. Program doesn't call deserializeJson()
  6. Program calls serializeJson(const JsonDocument&, ...)
  7. Program uses DynamicJsonDocument
  8. Program doesn't use String

Environment
Here is the environment that I'm using':

  • NXP iMX RT1061
  • Core/runtime: FreeRTOS
  • IDE: MCU Xpresso
Assignee
Assign to
Time tracking