Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
C-libcurl.model-body.mustache Maven / Gradle / Ivy
{{#models}}
{{#model}}
#include
#include
#include
#include "{{classname}}.h"
{{#isEnum}}
char* {{classFilename}}_{{classname}}_ToString({{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}) {
char *{{classname}}Array[] = { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
return {{classname}}Array[{{classname}}];
}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{classFilename}}_{{classname}}_FromString(char* {{classname}}) {
int stringToReturn = 0;
char *{{classname}}Array[] = { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
size_t sizeofArray = sizeof({{classname}}Array) / sizeof({{classname}}Array[0]);
while(stringToReturn < sizeofArray) {
if(strcmp({{classname}}, {{classname}}Array[stringToReturn]) == 0) {
return stringToReturn;
}
stringToReturn++;
}
return 0;
}
cJSON *{{classFilename}}_{{classname}}_convertToJSON({{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}) {
cJSON *item = cJSON_CreateObject();
{{#isString}}
if(cJSON_AddStringToObject(item, "{{{classname}}}", {{classFilename}}_{{{classname}}}_ToString({{{classname}}})) == NULL) {
goto fail;
}
{{/isString}}
{{#isNumeric}}
if(cJSON_AddNumberToObject(item, "{{{classname}}}", {{{classname}}}) == NULL) {
goto fail;
}
{{/isNumeric}}
{{#isBoolean}}
if(cJSON_AddBoolToObject(item, "{{{classname}}}", {{{classname}}}) == NULL) {
goto fail;
}
{{/isBoolean}}
return item;
fail:
cJSON_Delete(item);
return NULL;
}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{classFilename}}_{{classname}}_parseFromJSON(cJSON *{{classname}}JSON) {
{{projectName}}_{{classVarName}}_{{enumName}}_e *{{classname}} = NULL;
{{#isEnum}}
{{#isNumeric}}
cJSON *{{{classname}}}Var = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{classname}}}");
if(!cJSON_IsNumber({{{classname}}}Var))
{
goto end;
}
{{/isNumeric}}
{{#isString}}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{classname}}Variable;
cJSON *{{{classname}}}Var = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{classname}}}");
if(!cJSON_IsString({{{classname}}}Var) || ({{{classname}}}Var->valuestring == NULL)){
goto end;
}
{{classname}}Variable = {{classFilename}}_{{classname}}_FromString({{{classname}}}Var->valuestring);
{{/isString}}
{{/isEnum}}
return {{classname}}Variable;
end:
return 0;
}
{{/isEnum}}
{{^isEnum}}
{{#vars}}
{{^isContainer}}
{{^isModel}}
{{#isEnum}}
char* {{name}}{{classname}}_ToString({{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}) {
char* {{name}}Array[] = { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
return {{name}}Array[{{name}}];
}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{classname}}_FromString(char* {{name}}){
int stringToReturn = 0;
char *{{name}}Array[] = { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
size_t sizeofArray = sizeof({{name}}Array) / sizeof({{name}}Array[0]);
while(stringToReturn < sizeofArray) {
if(strcmp({{name}}, {{name}}Array[stringToReturn]) == 0) {
return stringToReturn;
}
stringToReturn++;
}
return 0;
}
{{/isEnum}}
{{/isModel}}
{{/isContainer}}
{{#isContainer}}
{{#items}}
{{^isModel}}
{{#isEnum}}
char* {{name}}{{classname}}_ToString({{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}) {
char *{{name}}Array[] = { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
return {{name}}Array[{{name}} - 1];
}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{classname}}_FromString(char* {{name}}) {
int stringToReturn = 0;
char *{{name}}Array[] = { "NULL"{{#allowableValues}}{{#enumVars}}, "{{{value}}}"{{/enumVars}}{{/allowableValues}} };
size_t sizeofArray = sizeof({{name}}Array) / sizeof({{name}}Array[0]);
while(stringToReturn < sizeofArray) {
if(strcmp({{name}}, {{name}}Array[stringToReturn]) == 0) {
return stringToReturn + 1;
}
stringToReturn++;
}
return 0;
}
{{/isEnum}}
{{/isModel}}
{{/items}}
{{/isContainer}}
{{/vars}}
{{classname}}_t *{{classname}}_create(
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
{{#isModel}}
{{#isEnum}}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{^isEnum}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isEnum}}
{{/isModel}}
{{#isUuid}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isUuid}}
{{#isEmail}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isEmail}}
{{#isFreeFormObject}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isNumeric}}
{{#isBoolean}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}{{^-last}},{{/-last}}
{{/isString}}
{{/isEnum}}
{{^isEnum}}
{{#isString}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isString}}
{{/isEnum}}
{{#isByteArray}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isByteArray}}
{{#isBinary}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isBinary}}
{{#isDate}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isDate}}
{{#isDateTime}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isArray}}
{{#isPrimitiveType}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{datatype}}_t *{{name}}{{^-last}},{{/-last}}
{{/isPrimitiveType}}
{{/isArray}}
{{#isMap}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{/isMap}}
{{/isContainer}}
{{/vars}}
) {
{{classname}}_t *{{classname}}_local_var = malloc(sizeof({{classname}}_t));
if (!{{classname}}_local_var) {
return NULL;
}
{{#vars}}
{{classname}}_local_var->{{{name}}} = {{{name}}};
{{/vars}}
return {{classname}}_local_var;
}
void {{classname}}_free({{classname}}_t *{{classname}}) {
if(NULL == {{classname}}){
return ;
}
listEntry_t *listEntry;
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
{{#isModel}}
{{^isEnum}}
if ({{{classname}}}->{{{name}}}) {
{{{complexType}}}_free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isEnum}}
{{/isModel}}
{{#isUuid}}
if ({{{classname}}}->{{{name}}}) {
free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isUuid}}
{{#isEmail}}
if ({{{classname}}}->{{{name}}}) {
free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isEmail}}
{{#isFreeFormObject}}
if ({{{classname}}}->{{{name}}}) {
object_free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{^isEnum}}
{{#isString}}
if ({{{classname}}}->{{{name}}}) {
free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isString}}
{{/isEnum}}
{{#isBinary}}
if ({{{classname}}}->{{{name}}}) {
free({{{classname}}}->{{{name}}}->data);
{{classname}}->{{name}} = NULL;
}
{{/isBinary}}
{{#isDate}}
if ({{{classname}}}->{{{name}}}) {
free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isDate}}
{{#isDateTime}}
if ({{{classname}}}->{{{name}}}) {
free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isArray}}
{{#isPrimitiveType}}
if ({{{classname}}}->{{{name}}}) {
list_ForEach(listEntry, {{classname}}->{{name}}) {
free(listEntry->data);
}
list_free({{classname}}->{{name}});
{{classname}}->{{name}} = NULL;
}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
if ({{{classname}}}->{{{name}}}) {
list_ForEach(listEntry, {{classname}}->{{name}}) {
{{complexType}}_free(listEntry->data);
}
list_free({{classname}}->{{name}});
{{classname}}->{{name}} = NULL;
}
{{/isPrimitiveType}}
{{/isArray}}
{{#isMap}}
if ({{{classname}}}->{{{name}}}) {
list_ForEach(listEntry, {{classname}}->{{name}}) {
keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data;
free (localKeyValue->key);
free (localKeyValue->value);
keyValuePair_free(localKeyValue);
}
list_free({{classname}}->{{name}});
{{classname}}->{{name}} = NULL;
}
{{/isMap}}
{{/isContainer}}
{{/vars}}
free({{classname}});
}
cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
cJSON *item = cJSON_CreateObject();
{{#vars}}
// {{{classname}}}->{{{name}}}
{{#required}}
{{^isEnum}}
if (!{{{classname}}}->{{{name}}}) {
goto fail;
}
{{/isEnum}}
{{/required}}
{{^required}}{{^isEnum}}if({{{classname}}}->{{{name}}}) { {{/isEnum}}{{/required}}
{{^isContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}
if(cJSON_AddNumberToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
goto fail; //Numeric
}
{{/isNumeric}}
{{#isBoolean}}
if(cJSON_AddBoolToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
goto fail; //Bool
}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{name}}}{{classname}}_ToString({{{classname}}}->{{{name}}})) == NULL)
{
goto fail; //Enum
}
{{/isString}}
{{/isEnum}}
{{^isEnum}}
{{#isString}}
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
goto fail; //String
}
{{/isString}}
{{/isEnum}}
{{#isByteArray}}
if(cJSON_AddNumberToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
goto fail; //Byte
}
{{/isByteArray}}
{{#isBinary}}
char* encoded_str_{{{name}}} = base64encode({{{classname}}}->{{{name}}}->data,{{{classname}}}->{{{name}}}->len);
if(cJSON_AddStringToObject(item, "{{{baseName}}}", encoded_str_{{{name}}}) == NULL) {
goto fail; //Binary
}
free (encoded_str_{{{name}}});
{{/isBinary}}
{{#isDate}}
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
goto fail; //Date
}
{{/isDate}}
{{#isDateTime}}
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
goto fail; //Date-Time
}
{{/isDateTime}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isModel}}
{{#isEnum}}
cJSON *{{{name}}}_enum_local_JSON = {{datatypeWithEnum}}_convertToJSON({{{classname}}}->{{{name}}});
if({{{name}}}_enum_local_JSON == NULL) {
goto fail; // enum
}
cJSON_AddItemToObject(item, "{{{baseName}}}", {{{name}}}_enum_local_JSON);
if(item->child == NULL) {
goto fail;
}
{{/isEnum}}
{{^isEnum}}
cJSON *{{{name}}}_local_JSON = {{complexType}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_convertToJSON({{{classname}}}->{{{name}}});
if({{{name}}}_local_JSON == NULL) {
goto fail; //model
}
cJSON_AddItemToObject(item, "{{{baseName}}}", {{{name}}}_local_JSON);
if(item->child == NULL) {
goto fail;
}
{{/isEnum}}
{{/isModel}}
{{#isUuid}}
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
goto fail; //uuid
}
{{/isUuid}}
{{#isEmail}}
if(cJSON_AddStringToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
goto fail; //Email
}
{{/isEmail}}
{{#isFreeFormObject}}
cJSON *{{{name}}}_object = object_convertToJSON({{{classname}}}->{{{name}}});
if({{{name}}}_object == NULL) {
goto fail; //model
}
cJSON_AddItemToObject(item, "{{{baseName}}}", {{{name}}}_object);
if(item->child == NULL) {
goto fail;
}
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isArray}}
{{#isPrimitiveType}}
cJSON *{{{name}}} = cJSON_AddArrayToObject(item, "{{{baseName}}}");
if({{{name}}} == NULL) {
goto fail; //primitive container
}
listEntry_t *{{{name}}}ListEntry;
list_ForEach({{{name}}}ListEntry, {{{classname}}}->{{{name}}}) {
{{#items}}
{{#isString}}
if(cJSON_AddStringToObject({{{name}}}, "", (char*){{{name}}}ListEntry->data) == NULL)
{
goto fail;
}
{{/isString}}
{{#isBoolean}}
if(cJSON_AddBoolToObject({{{name}}}, "", *(cJSON_bool *){{{name}}}ListEntry->data) == NULL)
{
goto fail;
}
{{/isBoolean}}
{{#isNumeric}}
if(cJSON_AddNumberToObject({{{name}}}, "", *(double *){{{name}}}ListEntry->data) == NULL)
{
goto fail;
}
{{/isNumeric}}
{{/items}}
}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
cJSON *{{{name}}} = cJSON_AddArrayToObject(item, "{{{baseName}}}");
if({{{name}}} == NULL) {
goto fail; //nonprimitive container
}
listEntry_t *{{{name}}}ListEntry;
if ({{{classname}}}->{{{name}}}) {
list_ForEach({{{name}}}ListEntry, {{classname}}->{{{name}}}) {
cJSON *itemLocal = {{complexType}}_convertToJSON({{#isEnum}}{{#items}}({{projectName}}_{{classVarName}}_{{enumName}}_e){{/items}}{{/isEnum}}{{{name}}}ListEntry->data);
if(itemLocal == NULL) {
goto fail;
}
cJSON_AddItemToArray({{{name}}}, itemLocal);
}
}
{{/isPrimitiveType}}
{{/isArray}}
{{#isMap}}
cJSON *{{{name}}} = cJSON_AddObjectToObject(item, "{{{baseName}}}");
if({{{name}}} == NULL) {
goto fail; //primitive map container
}
cJSON *localMapObject = {{{name}}};
listEntry_t *{{{name}}}ListEntry;
if ({{{classname}}}->{{{name}}}) {
list_ForEach({{{name}}}ListEntry, {{{classname}}}->{{{name}}}) {
keyValuePair_t *localKeyValue = (keyValuePair_t*){{{name}}}ListEntry->data;
{{#items}}
{{#isString}}
if(cJSON_AddStringToObject(localMapObject, localKeyValue->key, (char*)localKeyValue->value) == NULL)
{
goto fail;
}
{{/isString}}
{{#isNumeric}}
if(cJSON_AddNumberToObject(localMapObject, localKeyValue->key, *(double *)localKeyValue->value) == NULL)
{
goto fail;
}
{{/isNumeric}}
{{#isBoolean}}
if(cJSON_AddBoolToObject(localMapObject, localKeyValue->key, *(cJSON_bool *)localKeyValue->value) == NULL)
{
goto fail;
}
{{/isBoolean}}
{{/items}}
}
}
{{/isMap}}
{{/isContainer}}
{{^required}}
{{^isEnum}} } {{/isEnum}}
{{/required}}
{{/vars}}
return item;
fail:
if (item) {
cJSON_Delete(item);
}
return NULL;
}
{{classname}}_t *{{classname}}_parseFromJSON(cJSON *{{classname}}JSON){
{{classname}}_t *{{classname}}_local_var = NULL;
{{#vars}}
// {{{classname}}}->{{{name}}}
cJSON *{{{name}}} = cJSON_GetObjectItemCaseSensitive({{classname}}JSON, "{{{baseName}}}");
{{#required}}
if (!{{{name}}}) {
goto end;
}
{{/required}}
{{^isContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsNumber({{{name}}}))
{
goto end; //Numeric
}
{{/isNumeric}}
{{#isBoolean}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsBool({{{name}}}))
{
goto end; //Bool
}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
{{projectName}}_{{classVarName}}_{{enumName}}_e {{name}}Variable;
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsString({{{name}}}))
{
goto end; //Enum
}
{{name}}Variable = {{name}}{{classname}}_FromString({{{name}}}->valuestring);
{{/isString}}
{{/isEnum}}
{{^isEnum}}
{{#isString}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsString({{{name}}}))
{
goto end; //String
}
{{/isString}}
{{/isEnum}}
{{#isByteArray}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsNumber({{{name}}}))
{
goto end; //Byte
}
{{/isByteArray}}
{{#isBinary}}
binary_t* decoded_str_{{{name}}} = malloc(sizeof(struct binary_t));
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsString({{{name}}}))
{
goto end; //Binary
}
decoded_str_{{{name}}}->data = base64decode({{{name}}}->valuestring, strlen({{{name}}}->valuestring), &decoded_str_{{{name}}}->len);
if (!decoded_str_{{{name}}}->data) {
goto end;
}
{{/isBinary}}
{{#isDate}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsString({{{name}}}))
{
goto end; //Date
}
{{/isDate}}
{{#isDateTime}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsString({{{name}}}))
{
goto end; //DateTime
}
{{/isDateTime}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isModel}}
{{#isEnum}}
{{classFilename}}_{{datatypeWithEnum}}_e {{name}}_local_nonprim_enum;
{{^required}}if ({{{name}}}) { {{/required}}
{{{name}}}_local_nonprim_enum = {{datatypeWithEnum}}_parseFromJSON({{{name}}}); //enum model
{{/isEnum}}
{{^isEnum}}
{{^isFreeFormObject}}{{complexType}}{{/isFreeFormObject}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_t *{{name}}_local_nonprim = NULL;
{{^required}}if ({{{name}}}) { {{/required}}
{{{name}}}_local_nonprim = {{complexType}}{{#isFreeFormObject}}object{{/isFreeFormObject}}_parseFromJSON({{{name}}}); //nonprimitive
{{/isEnum}}
{{/isModel}}
{{#isUuid}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsString({{{name}}}))
{
goto end; //uuid
}
{{/isUuid}}
{{#isEmail}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsString({{{name}}}))
{
goto end; //email
}
{{/isEmail}}
{{#isFreeFormObject}}
object_t *{{name}}_local_object = NULL;
{{^required}}if ({{{name}}}) { {{/required}}
{{{name}}}_local_object = object_parseFromJSON({{{name}}}); //object
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isArray}}
{{#isPrimitiveType}}
list_t *{{{name}}}List;
{{^required}}if ({{{name}}}) { {{/required}}
cJSON *{{{name}}}_local;
if(!cJSON_IsArray({{{name}}})) {
goto end;//primitive container
}
{{{name}}}List = list_create();
cJSON_ArrayForEach({{{name}}}_local, {{{name}}})
{
{{#items}}
{{#isString}}
if(!cJSON_IsString({{{name}}}_local))
{
goto end;
}
list_addElement({{{name}}}List , strdup({{{name}}}_local->valuestring));
{{/isString}}
{{#isNumeric}}
if(!cJSON_IsNumber({{{name}}}_local))
{
goto end;
}
list_addElement({{{name}}}List , &{{{name}}}_local->valuedouble);
{{/isNumeric}}
{{#isBoolean}}
if(!cJSON_IsBool({{{name}}}_local))
{
goto end;
}
list_addElement({{{name}}}List , {{{name}}}_local->valueint);
{{/isBoolean}}
{{/items}}
}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
list_t *{{{name}}}List;
{{^required}}if ({{{name}}}) { {{/required}}
cJSON *{{{name}}}_local_nonprimitive;
if(!cJSON_IsArray({{{name}}})){
goto end; //nonprimitive container
}
{{{name}}}List = list_create();
cJSON_ArrayForEach({{{name}}}_local_nonprimitive,{{{name}}} )
{
if(!cJSON_IsObject({{{name}}}_local_nonprimitive)){
goto end;
}
{{#isEnum}}{{#items}}{{classFilename}}_{{datatypeWithEnum}}_e {{/items}}{{/isEnum}}{{^isEnum}}{{complexType}}_t *{{/isEnum}}{{{name}}}Item = {{complexType}}_parseFromJSON({{{name}}}_local_nonprimitive);
list_addElement({{{name}}}List, {{#isEnum}}{{#items}}(void *){{/items}}{{/isEnum}}{{{name}}}Item);
}
{{/isPrimitiveType}}
{{/isArray}}
{{#isMap}}
list_t *{{{name}}}List;
{{^required}}if ({{{name}}}) { {{/required}}
cJSON *{{{name}}}_local_map;
if(!cJSON_IsObject({{{name}}})) {
goto end;//primitive map container
}
{{{name}}}List = list_create();
keyValuePair_t *localMapKeyPair;
cJSON_ArrayForEach({{{name}}}_local_map, {{{name}}})
{
cJSON *localMapObject = {{{name}}}_local_map;
{{#items}}
{{#isString}}
if(!cJSON_IsString(localMapObject))
{
goto end;
}
localMapKeyPair = keyValuePair_create(strdup(localMapObject->string),strdup(localMapObject->valuestring));
{{/isString}}
{{#isBoolean}}
if(!cJSON_IsBool(localMapObject))
{
goto end;
}
localMapKeyPair = keyValuePair_create(strdup(localMapObject->string), &localMapObject->valueint);
{{/isBoolean}}
{{#isNumeric}}
if(!cJSON_IsNumber(localMapObject))
{
goto end;
}
localMapKeyPair = keyValuePair_create(strdup(localMapObject->string),&localMapObject->valuedouble );
{{/isNumeric}}
{{/items}}
list_addElement({{{name}}}List , localMapKeyPair);
}
{{/isMap}}
{{/isContainer}}
{{^required}}
}
{{/required}}
{{/vars}}
{{classname}}_local_var = {{classname}}_create (
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
{{#isModel}}
{{#isEnum}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}_local_nonprim_enum{{^required}} : -1{{/required}}{{^-last}},{{/-last}}
{{/isEnum}}
{{^isEnum}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}_local_nonprim{{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isEnum}}
{{/isModel}}
{{#isUuid}}
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isUuid}}
{{#isEmail}}
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isEmail}}
{{#isFreeFormObject}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}_local_object{{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}->valuedouble{{^required}} : 0{{/required}}{{^-last}},{{/-last}}
{{/isNumeric}}
{{#isBoolean}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}->valueint{{^required}} : 0{{/required}}{{^-last}},{{/-last}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
{{^required}}{{{name}}} ? {{/required}}{{name}}Variable{{^required}} : -1{{/required}}{{^-last}},{{/-last}}
{{/isString}}
{{/isEnum}}
{{^isEnum}}
{{#isString}}
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isString}}
{{/isEnum}}
{{#isByteArray}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}->valueint{{^required}} : 0{{/required}}{{^-last}},{{/-last}}
{{/isByteArray}}
{{#isBinary}}
{{^required}}{{{name}}} ? {{/required}}decoded_str_{{{name}}}{{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isBinary}}
{{#isDate}}
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isDate}}
{{#isDateTime}}
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isArray}}
{{#isPrimitiveType}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}List{{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}List{{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isPrimitiveType}}
{{/isArray}}
{{#isMap}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}List{{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isMap}}
{{/isContainer}}
{{/vars}}
);
return {{classname}}_local_var;
end:
{{#vars}}
{{^isContainer}}
{{^isPrimitiveType}}
{{#isModel}}
{{^isEnum}}
if ({{{name}}}_local_nonprim) {
{{complexType}}_free({{{name}}}_local_nonprim);
{{{name}}}_local_nonprim = NULL;
}
{{/isEnum}}
{{/isModel}}
{{/isPrimitiveType}}
{{/isContainer}}
{{/vars}}
return NULL;
}
{{/isEnum}}
{{/model}}
{{/models}}