8000 serialized() does not seem to work with progmem strings · Issue #1030 · bblanchon/ArduinoJson · GitHub
[go: up one dir, main page]

Skip to content
serialized() does not seem to work with progmem strings #1030
@Aircoookie

Description

@Aircoookie< 75EA /div>

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 :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugv6ArduinoJson 6

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0