summaryrefslogtreecommitdiff
path: root/json-glib/json-gobject.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@linux.intel.com>2009-10-28 16:05:19 +0000
committerEmmanuele Bassi <ebassi@linux.intel.com>2009-10-28 16:22:06 +0000
commit00b4d200849e232cd904d23d3593d6f95252b483 (patch)
tree802f6f6e4649fc9a1daa902bf7bfe6dc7c7e95f0 /json-glib/json-gobject.c
parentfc0607c740b153acc96e4df12a12b042e08e831b (diff)
downloadjson-glib-00b4d200849e232cd904d23d3593d6f95252b483.tar.gz
gobject: Uniform JSON<->GObject mapping code
Rename json_gobject_new() to json_gobject_deserialize(), and json_gobject_dump() to json_gobject_serialize(); this maps the JSON GBoxed API. Also for consistency, change the serialize() return value and the deserialize() argument to be JsonNodes of type JSON_NODE_OBJECT.
Diffstat (limited to 'json-glib/json-gobject.c')
-rw-r--r--json-glib/json-gobject.c82
1 files changed, 54 insertions, 28 deletions
diff --git a/json-glib/json-gobject.c b/json-glib/json-gobject.c
index 5fa18b6..53ee8fb 100644
--- a/json-glib/json-gobject.c
+++ b/json-glib/json-gobject.c
@@ -173,20 +173,7 @@ flags_from_string (GType type,
return ret;
}
-/**
- * json_gobject_new:
- * @gtype: the type of the #GObject to create
- * @object: a #JsonObject describing the object instance
- *
- * Creates a new #GObject of type @gtype, and constructs it
- * using the members of the passed #JsonObject
- *
- * Return value: (transfer full): The newly created #GObject
- * instance. Use g_object_unref() when done
- *
- * Since: 0.10
- */
-GObject *
+static GObject *
json_gobject_new (GType gtype,
JsonObject *object)
{
@@ -340,20 +327,7 @@ json_gobject_new (GType gtype,
return retval;
}
-/**
- * json_gobject_dump:
- * @gobject: a #GObject
- *
- * Creates a #JsonObject representing the passed #GObject
- * instance. Each member of the returned JSON object will
- * map to a property of the #GObject
- *
- * Return value: (transfer full): the newly created #JsonObject.
- * Use json_object_unref() when done
- *
- * Since: 0.10
- */
-JsonObject *
+static JsonObject *
json_gobject_dump (GObject *gobject)
{
JsonSerializableIface *iface = NULL;
@@ -721,6 +695,58 @@ json_serialize_pspec (const GValue *real_value,
}
/**
+ * json_gobject_deserialize:
+ * @gtype: the type of the #GObject to create
+ * @node: a #JsonNode of type %JSON_NODE_OBJECT describing the
+ * instance of type @gtype
+ *
+ * Creates a new #GObject of type @gtype, and constructs it
+ * using the members of the passed #JsonObject
+ *
+ * Return value: (transfer full): The newly created #GObject
+ * instance. Use g_object_unref() to free the resources
+ * allocated by this function
+ *
+ * Since: 0.10
+ */
+GObject *
+json_gobject_deserialize (GType gtype,
+ JsonNode *node)
+{
+ g_return_val_if_fail (g_type_is_a (gtype, G_TYPE_OBJECT), NULL);
+ g_return_val_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_OBJECT, NULL);
+
+ return json_gobject_new (gtype, json_node_get_object (node));
+}
+
+/**
+ * json_gobject_serialize:
+ * @gobject: a #GObject
+ *
+ * Creates a #JsonNode representing the passed #GObject
+ * instance. Each member of the returned JSON object will
+ * map to a property of the #GObject
+ *
+ * Return value: (transfer full): the newly created #JsonNode
+ * of type %JSON_NODE_OBJECT. Use json_node_free() to free
+ * the resources allocated by this function
+ *
+ * Since: 0.10
+ */
+JsonNode *
+json_gobject_serialize (GObject *gobject)
+{
+ JsonNode *retval;
+
+ g_return_val_if_fail (G_IS_OBJECT (gobject), NULL);
+
+ retval = json_node_new (JSON_NODE_OBJECT);
+ json_node_take_object (retval, json_gobject_dump (gobject));
+
+ return retval;
+}
+
+/**
* json_construct_gobject:
* @gtype: the #GType of object to construct
* @data: a JSON data stream