Skip to content

Commit

Permalink
Allow null values in JSON response
Browse files Browse the repository at this point in the history
  • Loading branch information
manup committed Mar 10, 2018
1 parent 9bcd5e6 commit cbf571d
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions json.cpp
Original file line number Diff line number Diff line change
@@ -124,6 +124,10 @@ QByteArray Json::serialize(const QVariant &data, bool &success)
str += join(pairs, ",");
str += "}";
}
else if (data.isNull())
{
str = "null";
}
else if((data.type() == QVariant::String) || (data.type() == QVariant::ByteArray)) // a string or a byte array?
{
str = sanitizeString(data.toString())
12 changes: 12 additions & 0 deletions resource.cpp
Original file line number Diff line number Diff line change
@@ -346,6 +346,13 @@ bool ResourceItem::setValue(qint64 val)

bool ResourceItem::setValue(const QVariant &val)
{
if (!val.isValid())
{
m_lastSet = QDateTime();
m_lastChanged = m_lastSet;
return true;
}

QDateTime now = QDateTime::currentDateTime();

if (m_rid.type == DataTypeString ||
@@ -459,6 +466,11 @@ void ResourceItem::setTimeStamps(const QDateTime &t)

QVariant ResourceItem::toVariant() const
{
if (!m_lastSet.isValid())
{
return QVariant();
}

if (m_rid.type == DataTypeString ||
m_rid.type == DataTypeTimePattern)
{

0 comments on commit cbf571d

Please sign in to comment.