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