@@ -82,10 +82,12 @@ class BaseCloudStorage {
8282 http::Response response = request.execute ();
8383 if (response.statusCode != 200 ) return false ;
8484
85- StaticJsonBuffer< 300 > jsonBuffer ;
86- JsonObject& root = jsonBuffer. parseObject ( response.body );
85+ DynamicJsonDocument root ( 1024 ) ;
86+ DeserializationError error = deserializeJson (root, response.body );
8787
88- return !root[" error" ]; // return isOk
88+ // return isOk
89+ if (error) return false ;
90+ return !root[" error" ];
8991 }
9092
9193 // Method for retrieving key/value pair
@@ -107,11 +109,13 @@ class BaseCloudStorage {
107109 if (response.statusCode != 200 ) return false ;
108110
109111 // Parse response body and extract the wanted value
110- StaticJsonBuffer<300 > jsonBuffer;
111- JsonObject& root = jsonBuffer.parseObject (response.body );
112+ DynamicJsonDocument root (1024 );
113+ DeserializationError error = deserializeJson (root, response.body );
114+
115+ // TODO: handle error
112116 return cloud_storage_utils::ResultWrapper<Ty>(
113117 !root[" error" ],
114- getValueByKey<Ty>(root[" result" ], key)
118+ getValueByKey<Ty>(root[" result" ]. as <JsonObject>() , key)
115119 );
116120 }
117121
@@ -133,10 +137,10 @@ class BaseCloudStorage {
133137 http::Response response = request.execute ();
134138 if (response.statusCode != 200 ) return false ;
135139
136- StaticJsonBuffer< 300 > jsonBuffer ;
137- JsonObject& root = jsonBuffer. parseObject ( response.body );
140+ DynamicJsonDocument root ( 1024 ) ;
141+ DeserializationError error = deserializeJson (root, response.body );
138142
139- return !root[" error" ]; // return isOk
143+ return !error && ! root[" error" ]; // return isOk
140144 }
141145
142146 // Method for popping values from arrays in the server
@@ -157,10 +161,10 @@ class BaseCloudStorage {
157161 http::Response response = request.execute ();
158162 if (response.statusCode != 200 ) return false ;
159163
160- StaticJsonBuffer< 300 > jsonBuffer ;
161- JsonObject& root = jsonBuffer. parseObject ( response.body );
164+ DynamicJsonDocument root ( 1024 ) ;
165+ DeserializationError error = deserializeJson (root, response.body );
162166
163- if (root[" error" ]) {
167+ if (error || root[" error" ]) {
164168 return false ;
165169 }
166170
@@ -262,12 +266,12 @@ class BaseCloudStorage {
262266 // String data(msg.data().c_str());
263267 // Serial.println("Got Msg: " + data);
264268
265- // parse response json
266- StaticJsonBuffer< 500 > jsonBuffer ;
267- JsonObject& root = jsonBuffer. parseObject ( msg.data ());
269+ // parse response json
270+ DynamicJsonDocument root ( 1024 ) ;
271+ DeserializationError error = deserializeJson (root, msg.data ());
268272
269273 String type = root[" type" ];
270- bool isError = root[" error" ];
274+ bool isError = error || root[" error" ];
271275
272276 // If the message is about the login, proccess it and update state
273277 if (type == " login" ) {
@@ -310,73 +314,68 @@ class BaseCloudStorage {
310314 template <class Type >
311315 String buildStoreObjectRequestJson (String key, Type value) {
312316 // Compose request json object
313- StaticJsonBuffer<200 > jsonBuffer;
314- JsonObject& root = jsonBuffer.createObject ();
317+ DynamicJsonDocument root (1024 );
315318 root[" username" ] = _username;
316319 root[" password" ] = _password;
317320 root[" key" ] = key;
318321 root[" value" ] = value;
319322
320323 // Return string form of the object
321324 String jsonString;
322- root. printTo ( jsonString);
325+ serializeJson (root, jsonString);
323326 return jsonString;
324327 }
325328
326329 // Utility method for constructing *Get* request json string
327330 String buildGetObjectRequestJson (String key) {
328331 // Compose request json object
329- StaticJsonBuffer<200 > jsonBuffer;
330- JsonObject& root = jsonBuffer.createObject ();
332+ DynamicJsonDocument root (1024 );
331333 root[" username" ] = _username;
332334 root[" password" ] = _password;
333335 root[" key" ] = key;
334336
335337 // Return string form of the object
336338 String jsonString;
337- root. printTo ( jsonString);
339+ serializeJson (root, jsonString);
338340 return jsonString;
339341 }
340342
341343 // Utility method for constructing *Add* request json string
342344 template <class Ty >
343345 String buildAddObjectRequestJson (String collectionKey, Ty object) {
344346 // Compose request json object
345- StaticJsonBuffer<200 > jsonBuffer;
346- JsonObject& root = jsonBuffer.createObject ();
347+ DynamicJsonDocument root (1024 );
347348 root[" username" ] = _username;
348349 root[" password" ] = _password;
349350 root[" collection_key" ] = collectionKey;
350351 root[" value" ] = object;
351352
352353 // Return string form of the object
353354 String jsonString;
354- root. printTo ( jsonString);
355+ serializeJson (root, jsonString);
355356 return jsonString;
356357 }
357358
358359 // Utility method for constructing *Pop* request json string
359360 String buildPopRequestJson (String collectionKey, PopFrom popFrom) {
360361 // Compose request json object
361- StaticJsonBuffer<200 > jsonBuffer;
362- JsonObject& root = jsonBuffer.createObject ();
362+ DynamicJsonDocument root (1024 );
363363 root[" username" ] = _username;
364364 root[" password" ] = _password;
365365 root[" collection_key" ] = collectionKey;
366366 root[" position" ] = (popFrom == PopFrom_Start? " first" : " last" );
367367
368368 // Return string form of the object
369369 String jsonString;
370- root. printTo ( jsonString);
370+ serializeJson (root, jsonString);
371371 return jsonString;
372372 }
373373
374374 // Utility method for constructing generic *Atomic* request json string
375375 template <class Ty >
376376 String buildAtomicRequestJson (String key, String action, Ty value) {
377377 // Compose request json object
378- StaticJsonBuffer<200 > jsonBuffer;
379- JsonObject& root = jsonBuffer.createObject ();
378+ DynamicJsonDocument root (1024 );
380379 root[" username" ] = _username;
381380 root[" password" ] = _password;
382381 root[" key" ] = key;
@@ -385,7 +384,7 @@ class BaseCloudStorage {
385384
386385 // Return string form of the object
387386 String jsonString;
388- root. printTo ( jsonString);
387+ serializeJson (root, jsonString);
389388 return jsonString;
390389 }
391390
@@ -424,27 +423,27 @@ class BaseCloudStorage {
424423 if (response.statusCode != 200 ) return false ;
425424
426425 // Parse response body and extract the wanted value
427- StaticJsonBuffer<300 > jsonBuffer;
428- JsonObject& root = jsonBuffer.parseObject (response.body );
426+ DynamicJsonDocument root (1024 );
427+ DeserializationError error = deserializeJson (root, response.body );
428+ // TODO: handle error
429429 return cloud_storage_utils::ResultWrapper<Ty>(
430430 !root[" error" ],
431- getValueByKey<Ty>(root[" result" ], key)
431+ getValueByKey<Ty>(root[" result" ]. as <JsonObject>() , key)
432432 );
433433 }
434434
435435 // Utility method for constructing generic *Aggregate* request json string
436436 String buildAggregationRequestJson (String collectionKey, String action) {
437437 // Compose request json object
438- StaticJsonBuffer<200 > jsonBuffer;
439- JsonObject& root = jsonBuffer.createObject ();
438+ DynamicJsonDocument root (1024 );
440439 root[" username" ] = _username;
441440 root[" password" ] = _password;
442441 root[" collection_key" ] = collectionKey;
443442 root[" action" ] = action;
444443
445444 // Return string form of the object
446445 String jsonString;
447- root. printTo ( jsonString);
446+ serializeJson (root, jsonString);
448447 return jsonString;
449448 }
450449
@@ -468,8 +467,9 @@ class BaseCloudStorage {
468467 if (response.statusCode != 200 ) return false ;
469468
470469 // Parse response body and extract the wanted value
471- StaticJsonBuffer<300 > jsonBuffer;
472- JsonObject& root = jsonBuffer.parseObject (response.body );
470+ DynamicJsonDocument root (1024 );
471+ DeserializationError error = deserializeJson (root, response.body );
472+ // TODO: handle errors
473473 return cloud_storage_utils::ResultWrapper<Ty>(
474474 !root[" error" ],
475475 root[" result" ]
0 commit comments