Skip to content

Commit d7aebba

Browse files
committed
Add ability to detect null string (happens when nodes gets deleted)
1 parent 08bed6b commit d7aebba

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/FirebaseObject.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,18 @@ float FirebaseObject::getFloat(const String& path) const {
5454

5555
String FirebaseObject::getString(const String& path) const {
5656
JsonVariant variant = getJsonVariant(path);
57-
if (!variant.is<const char *>()) {
57+
if (!variant.is<const char *>() || isNullString(path)) {
5858
error_ = "failed to convert to string";
5959
return "";
6060
}
6161
return static_cast<const char*>(variant);
6262
}
6363

64+
bool FirebaseObject::isNullString(const String& path) const {
65+
JsonVariant variant = getJsonVariant(path);
66+
return variant.is<const char *>() && variant.asString() == NULL;
67+
}
68+
6469
JsonVariant FirebaseObject::getJsonVariant(const String& path) const {
6570
String key(path);
6671
char* start = &key[0];

src/FirebaseObject.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ class FirebaseObject {
4343
*/
4444
bool getBool(const String& path = "") const;
4545

46+
/**
47+
* Returns true if specified path is NULL string.
48+
* Useful to detect tree deletions.
49+
* \param optional path in the JSON object.
50+
* \return result as a bool.
51+
*/
52+
bool isNullString(const String& path = "") const;
53+
4654
/**
4755
* Return the value as an int.
4856
* \param optional path in the JSON object.

0 commit comments

Comments
 (0)