Check cJSON_IsNull when the data type is datetime (#13884)

This commit is contained in:
Hui Yu 2022-11-04 12:26:47 +08:00 committed by GitHub
parent c71ec554dc
commit c3abdb6c57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -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
}
@ -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}}

View File

@ -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
}
@ -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
);