[qt5cpp] Add nullptr guard to prevent crash when empty model is being serialized (#7434)

* Small fixes to prevent crash when empty json body is provided.

* Updated PetStore example for Qt5
This commit is contained in:
etherealjoy 2018-01-19 08:36:45 +01:00 committed by William Cheng
parent 30c1448d78
commit ea4b948428
4 changed files with 6 additions and 2 deletions

View File

@ -3,6 +3,8 @@
#define {{prefix}}_HELPERS_H #define {{prefix}}_HELPERS_H
#include <QJsonValue> #include <QJsonValue>
#include <QList>
#include <QMap>
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
namespace {{this}} { namespace {{this}} {

View File

@ -105,7 +105,7 @@ QJsonObject*
QJsonObject* obj = new QJsonObject(); QJsonObject* obj = new QJsonObject();
{{#vars}} {{#vars}}
{{^isContainer}}{{#complexType}}{{^isString}}{{^isDate}}{{^isDateTime}}{{^isByteArray}} {{^isContainer}}{{#complexType}}{{^isString}}{{^isDate}}{{^isDateTime}}{{^isByteArray}}
if({{name}}->isSet()){ if(({{name}} != nullptr) && ({{name}}->isSet())){
toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}")); toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}"));
}{{/isByteArray}}{{/isDateTime}}{{/isDate}}{{/isString}}{{#isString}} }{{/isByteArray}}{{/isDateTime}}{{/isDate}}{{/isString}}{{#isString}}
if({{name}} != nullptr && *{{name}} != QString("")){ if({{name}} != nullptr && *{{name}} != QString("")){

View File

@ -14,6 +14,8 @@
#define SWG_HELPERS_H #define SWG_HELPERS_H
#include <QJsonValue> #include <QJsonValue>
#include <QList>
#include <QMap>
namespace Swagger { namespace Swagger {

View File

@ -122,7 +122,7 @@ SWGPet::asJsonObject() {
obj->insert("id", QJsonValue(id)); obj->insert("id", QJsonValue(id));
} }
if(category->isSet()){ if((category != nullptr) && (category->isSet())){
toJsonValue(QString("category"), category, obj, QString("SWGCategory")); toJsonValue(QString("category"), category, obj, QString("SWGCategory"));
} }