summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gmail.com>2020-01-14 11:29:08 +0000
committerEmmanuele Bassi <ebassi@gmail.com>2020-01-14 11:29:08 +0000
commitf2c5b4e2fec975b798ff5dba553c15ffc69b9d82 (patch)
tree8779604ce6b38eadf97ea9154b95c828106a6199
parent0ce64cc440d4e3e34235097f868c81a21c3fe4c3 (diff)
parentc6cab478f22d2e47c41fe0f1fef7f0eaf4a5d869 (diff)
downloadjson-glib-f2c5b4e2fec975b798ff5dba553c15ffc69b9d82.tar.gz
Merge branch 'fix/default-deserialization' into 'master'
Fix default deserialization method. See merge request GNOME/json-glib!16
-rw-r--r--json-glib/json-serializable.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/json-glib/json-serializable.c b/json-glib/json-serializable.c
index eb7556d..8eb64d7 100644
--- a/json-glib/json-serializable.c
+++ b/json-glib/json-serializable.c
@@ -77,6 +77,11 @@ json_serializable_serialize_property (JsonSerializable *serializable,
* Asks a #JsonSerializable implementation to deserialize the
* property contained inside @property_node into @value.
*
+ * The @value can be:
+ * - an empty #GValue initialized by %G_VALUE_INIT, which will be automatically
+ * initialized with the expected type of the property (since JSON-GLib 1.6)
+ * - a #GValue initialized with the expected type of the property
+ *
* Return value: %TRUE if the property was successfully deserialized.
*/
gboolean
@@ -111,6 +116,10 @@ json_serializable_real_deserialize (JsonSerializable *serializable,
JsonNode *node)
{
JSON_NOTE (GOBJECT, "Default deserialization for property '%s'", pspec->name);
+
+ if (!G_IS_VALUE (value))
+ g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+
return json_deserialize_pspec (value, pspec, node);
}