YAMLDuino
YAMLDuino copied to clipboard
ArduinoJson binding issue with lists of objects
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:
-
The manual way: use YAMLDuino to convert the YAML to JSON, then deserialize that JSON using ArduinoJSON, then reserialize using ArduinoJSON.
-
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.