|
1 | 1 | #include <ArduinoJson.h> // optional |
2 | 2 | //#include <cJSON.h> // implicit with esp32, otherwise optional |
3 | | -#include <esp32-yaml.hpp> |
| 3 | +#include <ArduinoYaml.h> |
4 | 4 |
|
5 | 5 |
|
6 | 6 | // sorry about the notation, but it looks nicer than chunk-splitting+quoting |
@@ -83,28 +83,29 @@ void setup() |
83 | 83 | YAML_LOG_n("YAML=>JSON and JSON=>YAML using ArduinoJson\n\n"); |
84 | 84 |
|
85 | 85 | { |
86 | | - YAML_LOG_n( "[TEST #%d] YAML stream to JsonObject -> deserializeYml(json_obj, yaml_stream):", test_number++ ); |
87 | | - JsonObject json_obj; |
| 86 | + YAML_LOG_n( "[TEST #%d] YAML stream to JsonObject -> deserializeYml(json_doc, yaml_stream):", test_number++ ); |
| 87 | + DynamicJsonDocument json_doc(yaml_str_size*2); |
88 | 88 | String yaml_str = String( yaml_example_str ); |
89 | 89 | StringStream yaml_stream( yaml_str ); |
90 | | - auto err = deserializeYml( json_obj, yaml_stream ); // deserialize yaml stream to JsonObject |
| 90 | + auto err = deserializeYml( json_doc, yaml_stream ); // deserialize yaml stream to JsonDocument |
91 | 91 | if( err ) { |
92 | 92 | YAML_LOG_n("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() ); |
93 | 93 | return; |
94 | 94 | } |
95 | | - const size_t bytes_out = serializeJsonPretty( json_obj, Serial ); // print deserialized JsonObject |
| 95 | + const size_t bytes_out = serializeJsonPretty( json_doc, Serial ); // print deserialized JsonObject |
96 | 96 | YAML_LOG_n("[YAML=>JsonObject] yaml bytes in=%d, json bytes out=%d\n\n", yaml_str_size, bytes_out); |
97 | 97 | } |
98 | 98 |
|
99 | 99 |
|
100 | 100 | { |
101 | | - YAML_LOG_n( "[TEST #%d] YAML string to JsonObject -> deserializeYml(json_obj, yaml_example_str):", test_number++ ); |
102 | | - JsonObject json_obj; |
103 | | - auto err = deserializeYml( json_obj, yaml_example_str ); // deserialize yaml string to JsonObject |
| 101 | + YAML_LOG_n( "[TEST #%d] YAML string to JsonObject -> deserializeYml(json_doc, yaml_example_str):", test_number++ ); |
| 102 | + DynamicJsonDocument json_doc(yaml_str_size*2); |
| 103 | + auto err = deserializeYml( json_doc, yaml_example_str ); // deserialize yaml string to JsonDocument |
104 | 104 | if( err ) { |
105 | 105 | YAML_LOG_n("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() ); |
106 | 106 | return; |
107 | 107 | } |
| 108 | + JsonObject json_obj = json_doc.as<JsonObject>(); |
108 | 109 | const size_t bytes_out = serializeJsonPretty( json_obj, Serial ); // print deserialized JsonObject |
109 | 110 | YAML_LOG_n("[YAML=>JsonObject] yaml bytes in=%d, json bytes out=%d\n\n", yaml_str_size, bytes_out); |
110 | 111 | } |
@@ -151,13 +152,15 @@ void setup() |
151 | 152 | } |
152 | 153 |
|
153 | 154 |
|
| 155 | + #if defined USE_STREAM_TO_STREAM // stream to stream unavailable on esp8266 (not enough memory) |
154 | 156 | { |
155 | 157 | YAML_LOG_n( "[TEST #%d] JSON stream to JsonObject to YAML stream -> serializeYml(stream_in, Serial):", test_number++ ); |
156 | 158 | String str_json = String( json_example_str ); |
157 | 159 | StringStream stream_in( str_json ); |
158 | 160 | const size_t bytes_out = serializeYml( stream_in, Serial ); |
159 | 161 | YAML_LOG_n("[JSON=>JsonObject=>YAML] json bytes in=%d, yaml bytes out=%d\n", json_str_size, bytes_out); |
160 | 162 | } |
| 163 | + #endif |
161 | 164 |
|
162 | 165 |
|
163 | 166 | YAML_LOG_n("ArduinoJson tests complete"); |
|
0 commit comments