Fixes Issue #6841, Map for accessing additionalProperties is generated. (#6886)

The issue #6884 is still present and requires fixing outside of mustache file as well.
This commit is contained in:
etherealjoy 2017-11-12 15:16:26 +01:00 committed by William Cheng
parent 6739481a5d
commit ca58053339

View File

@ -58,11 +58,27 @@ void
void
{{classname}}::fromJsonObject(QJsonObject &pJson) {
{{#vars}}
{{^isContainer}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}");{{/isContainer}}
{{#isContainer}}
{{^isContainer}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}");{{/isContainer}}
{{#isListContainer}}
{{#complexType}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}");{{/complexType}}
{{^complexType}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{items.baseType}}");{{/complexType}}
{{/isContainer}}
{{/isListContainer}}
{{#isMapContainer}}
if( pJson["{{baseName}}"].isObject()){
auto varmap = pJson["{{baseName}}"].toObject().toVariantMap();
if(varmap.count() > 0){
for(auto val : varmap.keys() ){
{
{{items.baseType}} *{{name}}_item = new {{items.baseType}}();
auto jsonval = QJsonValue::fromVariant(varmap[val]);
::{{cppNamespace}}::setValue(&{{name}}_item, jsonval, "{{items.baseType}}", "{{items.baseType}}");
{{name}}->insert({{name}}->end(), val, {{name}}_item);
}
}
}
}
{{/isMapContainer}}
{{/vars}}
}
@ -83,14 +99,28 @@ QJsonObject*
toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}"));{{/complexType}}{{^complexType}}
if({{name}} != nullptr && *{{name}} != nullptr) {
obj->insert("{{name}}", QJsonValue(*{{name}}));
}{{/complexType}}{{/isContainer}}{{#isContainer}}
}{{/complexType}}{{/isContainer}}{{#isListContainer}}
QJsonArray {{name}}JsonArray;
toJsonArray((QList<void*>*){{name}}, &{{name}}JsonArray, "{{name}}", "{{complexType}}");
obj->insert("{{baseName}}", {{name}}JsonArray);{{/isContainer}}{{/complexType}}{{^complexType}}{{^isContainer}}
obj->insert("{{baseName}}", QJsonValue({{name}}));{{/isContainer}}{{#isContainer}}
obj->insert("{{baseName}}", {{name}}JsonArray);{{/isListContainer}}{{#isMapContainer}}
QJsonArray {{name}}JsonArray;
for(auto keyval : {{name}}->keys()){
QJsonObject {{name}}_jobj;
toJsonValue(keyval, ((*{{name}})[keyval]), &{{name}}_jobj, "{{complexType}}");
{{name}}JsonArray.append({{name}}_jobj);
}
obj->insert("{{baseName}}", {{name}}JsonArray);{{/isMapContainer}}{{/complexType}}{{^complexType}}{{^isContainer}}
obj->insert("{{baseName}}", QJsonValue({{name}}));{{/isContainer}}{{#isListContainer}}
QJsonArray {{name}}JsonArray;
toJsonArray((QList<void*>*){{name}}, &{{name}}JsonArray, "{{name}}", "{{items.baseType}}");
obj->insert("{{baseName}}", {{name}}JsonArray);{{/isContainer}}{{/complexType}}
obj->insert("{{baseName}}", {{name}}JsonArray);{{/isListContainer}}{{#isMapContainer}}
QJsonArray {{name}}JsonArray;
for(auto keyval : {{name}}->keys()){
QJsonObject {{name}}_jobj;
toJsonValue(keyval, ((*{{name}})[keyval]), &{{name}}_jobj, "{{items.baseType}}");
{{name}}JsonArray.append(portsobj);
}
obj->insert("{{baseName}}", {{name}}JsonArray);{{/isMapContainer}}{{/complexType}}
{{/vars}}
return obj;