tobozo / YAMLDuino

YAML <=> JSON converter for ESP32, ESP8266, RP2040 and possibly other devices
Other
42 stars 2 forks source link

ArduinoJson binding issue with lists of objects #19

Closed robb-brown closed 4 months ago

robb-brown commented 7 months ago

There seems to be a problem with the ArduinoJson binding specifically affecting lists of objects. Here is a minimal example that takes a simple YAML list of objects, deserializes it, then reserializes it to Serial. It does this twice, in two different ways:

1) The manual way: use YAMLDuino to convert the YAML to JSON, then deserialize that JSON using ArduinoJSON, then reserialize using ArduinoJSON.

2) Use YAMLDuino + ArduinoJson bindings to deserialize the YAML directly to an ArduinoJson document, then serialize to JSON.

(1) works, (2) loses the content of the objects.

Code:

// #1
YAMLNode yamlnode;
JsonDocument doc;
String buffer;
deserializeYml(yamlnode,"[{\"A\":\"1\"},{\"B\":\"1\"}]");
serializeYml(yamlnode.getDocument(),buffer,OUTPUT_JSON_PRETTY);
deserializeJson(doc,buffer);
Serial.println("YAML -> JSON -> deserializeJson -> serializeJson");
serializeJson(doc,Serial);
Serial.println("\n");

// #2
deserializeYml(doc,"[{\"A\":\"1\"},{\"B\":\"1\"}]");
Serial.println("YAML -> deserializeYml -> serializeJson");
serializeJson(doc,Serial);
Serial.println();

Output:

YAML -> JSON -> deserializeJson -> serializeJson
[{"A":1},{"B":1}]

YAML -> deserializeYml -> serializeJson
{"":[{},{}]}

I also tried #1 with OUTPUT_JSON instead of OUTPUT_JSON_PRETTY and it still worked fine, so the issue seems to be somewhere in the bindings themselves.

tobozo commented 4 months ago

hi,

the library was just migrated to use ArduinoJSON 7.x only, so things may have changed to the better .... or gotten worse :-)

either way I suggest you update to version 1.4.1 of YAMLDuino (currently propagating to platformio and arduino library registries) and reopen this issue if the problem is still there