]> granicus.if.org Git - json-c/commitdiff
Issue #539: reset the serializer when json_object_set_double() is called and the...
authorEric Haszlakiewicz <erh+git@nimenees.com>
Thu, 13 Feb 2020 03:11:10 +0000 (03:11 +0000)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Thu, 13 Feb 2020 03:11:10 +0000 (03:11 +0000)
json_object.c
tests/test_set_value.c
tests/test_set_value.expected

index 458014c2051195ea602184e50fa82b074f83070c..1d41f6a92eb5bf8ff3bf6ee05a880e673887df31 100644 (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;
 }
 
index 1f80b0ea3a1245c5e256b9dc22268290cf12d16e..50957d2f3f038beced5e1cad5489c1adb0a45edd 100644 (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;
 }
index 6a900f9a69e75fda044d6305b9808531279276f7..4cbd5bcd9bccf1c17b171f9bde304990ffb1c649 100644 (file)
@@ -3,4 +3,5 @@ INT64 PASSED
 BOOL PASSED
 DOUBLE PASSED
 STRING PASSED
+PARSE AND SET PASSED
 PASSED