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
  • #1030
Closed
Open
Issue created Jun 20, 2019 by Administrator@rootContributor

serialized() does not seem to work with progmem strings

Created by: Aircoookie

Hi, I love your library, awesome work! It seems like there is an issue with type conversation when using serialized() with flash strings (or I'm just missing something obvious). Just gibberish is printed. This is on an ESP8266, same result with core versions 2.4.2 and 2.5.2, Arduino 1.8.9, ArduinoJson v6.11.

MVCE:

#include <ArduinoJson.h>

const char prog_string_direct[] PROGMEM = "This works";
const char prog_string_serialized[] PROGMEM = "\"This doesn't\"";
  
void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.println("start");
  DynamicJsonDocument doc(1024);
  doc["direct"] = reinterpret_cast<const __FlashStringHelper*>(prog_string_direct);
  doc["serialized"] = serialized(reinterpret_cast<const __FlashStringHelper*>(prog_string_serialized));
  serializeJsonPretty(doc, Serial);
}

void loop() {
}

Output to serial:

{
  "direct": "This works",
  "serialized": W⸮/H⸮
}

Leaving out the reinterpret_cast crashes the system as you described here

doc["serialized"] = serialized(prog_string_serialized); //crashes on serialization
doc["serialized"] = serialized(String(prog_string_serialized));

works, but I am worried about heap fragmentation (progmem string is several kB in my application)

Is this a bug or is there a way for me to get this to work? Thank you :)

Assignee
Assign to
Time tracking