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
  • #1368
Closed
Open
Issue created Sep 05, 2020 by Administrator@rootContributor

Why adding (char*)0 to JsonArray returns false?

Created by: dyarkovoy

According to the docs, JsonVariant::add() returns

  • true if the value was successfully added.
  • false if there was not enough memory in the JsonDocument.

However, when I do array.add((char*)0), the returned value is always false, even if the new slot was added successfully. I traced it down to this piece in VariantData.hpp:

  template <typename TStoragePolicy>
  bool setString(const char *s, TStoragePolicy storage_policy) {
    if (s) {
      setString(make_not_null(s), storage_policy);
      return true;
    } else {
      setType(VALUE_IS_NULL);
      return false;
    }
  }

I guess this assumes that if s==nullptr, then we could not allocate mem somewhere earlier, But what if we purposefully pass nullptr? This may seem like a minor glitch, but my use case is to make sure there's always enough space in the doc when populating it, so I check the return of every set() and add() and throw if any returns false, to preserve document consistency.

Maybe there's anoter [proper] way to assign null to a JsonVariant?

If I'm not overlooking something and this is a glitch indeed, then it raises another question, maybe we should have a special-case-null-variant static, or separate setNull() / addNull() methods, like the isNull() we have already?

Assignee
Assign to
Time tracking