Browse Source

Issue #539: reset the serializer when json_object_set_double() is called and the current serializer is the one that json_object_new_double_s() used.

tags/json-c-0.14-20200419
Eric Haszlakiewicz 5 years ago
parent
commit
ae13ca524a
3 changed files with 11 additions and 2 deletions
  1. +2
    -0
      json_object.c
  2. +8
    -2
      tests/test_set_value.c
  3. +1
    -0
      tests/test_set_value.expected

+ 2
- 0
json_object.c View File

@@ -999,6 +999,8 @@ int json_object_set_double(struct json_object *jso,double new_value){
if (!jso || jso->o_type!=json_type_double)
return 0;
jso->o.c_double=new_value;
if (jso->_to_json_string == &json_object_userdata_to_json_string)
json_object_set_serializer(jso, NULL, NULL, NULL);
return 1;
}



+ 8
- 2
tests/test_set_value.c View File

@@ -45,8 +45,14 @@ int main(int argc, char **argv)
assert (strcmp(json_object_get_string(tmp),SHORT)==0);
json_object_put(tmp);
printf("STRING PASSED\n");

tmp = json_tokener_parse("1.234");
json_object_set_double(tmp, 12.3);
const char *serialized = json_object_to_json_string(tmp);
fprintf(stderr, "%s\n", serialized);
assert(strncmp(serialized, "12.3", 4)==0);
printf("PARSE AND SET PASSED\n");

printf("PASSED\n");
return 0;
}

+ 1
- 0
tests/test_set_value.expected View File

@@ -3,4 +3,5 @@ INT64 PASSED
BOOL PASSED
DOUBLE PASSED
STRING PASSED
PARSE AND SET PASSED
PASSED

Loading…
Cancel
Save