summaryrefslogtreecommitdiff
path: root/json-glib
diff options
context:
space:
mode:
Diffstat (limited to 'json-glib')
-rw-r--r--json-glib/json-gvariant.c6
-rw-r--r--json-glib/tests/gvariant.c4
2 files changed, 9 insertions, 1 deletions
diff --git a/json-glib/json-gvariant.c b/json-glib/json-gvariant.c
index 9c4ce1a..f8058df 100644
--- a/json-glib/json-gvariant.c
+++ b/json-glib/json-gvariant.c
@@ -1193,7 +1193,11 @@ json_to_gvariant_recurse (JsonNode *json_node,
break;
case G_VARIANT_CLASS_DOUBLE:
- if (json_node_assert_type (json_node, JSON_NODE_VALUE, G_TYPE_DOUBLE, error))
+ /* Doubles can look like ints to the json parser: when they don't have a dot */
+ if (JSON_NODE_TYPE (json_node) == JSON_NODE_VALUE &&
+ json_node_get_value_type (json_node) == G_TYPE_INT64)
+ variant = g_variant_new_double (json_node_get_int (json_node));
+ else if (json_node_assert_type (json_node, JSON_NODE_VALUE, G_TYPE_DOUBLE, error))
variant = g_variant_new_double (json_node_get_double (json_node));
break;
diff --git a/json-glib/tests/gvariant.c b/json-glib/tests/gvariant.c
index 38c56b7..701997d 100644
--- a/json-glib/tests/gvariant.c
+++ b/json-glib/tests/gvariant.c
@@ -44,6 +44,9 @@ static const TestCase two_way_test_cases[] =
/* double */
{ "/double", "(d)", "(1.23,)", "[1.23]" },
+ /* double */
+ { "/double-whole", "(d)", "(123.0,)", "[123]" },
+
/* string */
{ "/string", "(s)", "('hello world!',)", "[\"hello world!\"]" },
@@ -155,6 +158,7 @@ static const TestCase json_to_gvariant_test_cases[] =
{ "/string-to-int64", "(x)", "(int64 -666999666999,)", "[\"-666999666999\"]" },
{ "/string-to-uint64", "(t)", "(uint64 1999999999999999,)", "[\"1999999999999999\"]" },
{ "/string-to-double", "(d)", "(1.23,)", "[\"1.23\"]" },
+ { "/string-to-double-whole", "(d)", "(123.0,)", "[\"123\"]" },
};
static void