Skip to content

Commit

Permalink
Check cJSON_IsNull when the data type is datetime (#13884)
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuhui authored Nov 4, 2022
1 parent c71ec55 commit c3abdb6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ fail:
{{/isDate}}
{{#isDateTime}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsString({{{name}}}))
if(!cJSON_IsString({{{name}}}) && !cJSON_IsNull({{{name}}}))
{
goto end; //DateTime
}
Expand Down Expand Up @@ -893,7 +893,7 @@ fail:
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isDate}}
{{#isDateTime}}
{{^required}}{{{name}}} ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{^required}}{{{name}}} && !cJSON_IsNull({{{name}}}) ? {{/required}}strdup({{{name}}}->valuestring){{^required}} : NULL{{/required}}{{^-last}},{{/-last}}
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isContainer}}
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/c/model/order.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){
// order->ship_date
cJSON *ship_date = cJSON_GetObjectItemCaseSensitive(orderJSON, "shipDate");
if (ship_date) {
if(!cJSON_IsString(ship_date))
if(!cJSON_IsString(ship_date) && !cJSON_IsNull(ship_date))
{
goto end; //DateTime
}
Expand Down Expand Up @@ -181,7 +181,7 @@ order_t *order_parseFromJSON(cJSON *orderJSON){
id ? id->valuedouble : 0,
pet_id ? pet_id->valuedouble : 0,
quantity ? quantity->valuedouble : 0,
ship_date ? strdup(ship_date->valuestring) : NULL,
ship_date && !cJSON_IsNull(ship_date) ? strdup(ship_date->valuestring) : NULL,
status ? statusVariable : -1,
complete ? complete->valueint : 0
);
Expand Down

0 comments on commit c3abdb6

Please sign in to comment.