forked from loafle/openapi-generator-original
* cJSON generate unformatted json to save memory during large objects handling * update sample * add option to use cjson print unforamtted in client * remove unused test template files * add new samples * update workflow * update doc * fix model filename * fix inclulde --------- Co-authored-by: Hemant Zope <42613258+zhemant@users.noreply.github.com> Co-authored-by: Hemant Zope <hemantzope2008@gmail.com>
52 lines
870 B
C
52 lines
870 B
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include "object.h"
|
|
|
|
object_t *object_create() {
|
|
object_t *object = calloc(1, sizeof(object_t));
|
|
|
|
return object;
|
|
}
|
|
|
|
void object_free(object_t *object) {
|
|
if (!object) {
|
|
return ;
|
|
}
|
|
|
|
if (object->temporary) {
|
|
free(object->temporary);
|
|
object->temporary = NULL;
|
|
}
|
|
|
|
free (object);
|
|
}
|
|
|
|
cJSON *object_convertToJSON(object_t *object) {
|
|
if (!object) {
|
|
return NULL;
|
|
}
|
|
|
|
if (!object->temporary) {
|
|
return cJSON_Parse("null");
|
|
}
|
|
|
|
return cJSON_Parse(object->temporary);
|
|
}
|
|
|
|
object_t *object_parseFromJSON(cJSON *json){
|
|
if (!json) {
|
|
goto end;
|
|
}
|
|
|
|
object_t *object = object_create();
|
|
if (!object) {
|
|
goto end;
|
|
}
|
|
object->temporary = cJSON_PrintUnformatted(json);
|
|
return object;
|
|
|
|
end:
|
|
return NULL;
|
|
}
|