diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2009-10-28 16:05:19 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2009-10-28 16:22:06 +0000 |
commit | 00b4d200849e232cd904d23d3593d6f95252b483 (patch) | |
tree | 802f6f6e4649fc9a1daa902bf7bfe6dc7c7e95f0 | |
parent | fc0607c740b153acc96e4df12a12b042e08e831b (diff) | |
download | json-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.
-rw-r--r-- | doc/reference/json-glib-sections.txt | 4 | ||||
-rw-r--r-- | json-glib/json-gobject.c | 82 | ||||
-rw-r--r-- | json-glib/json-gobject.h | 10 |
3 files changed, 61 insertions, 35 deletions
diff --git a/doc/reference/json-glib-sections.txt b/doc/reference/json-glib-sections.txt index 428767d..e47c309 100644 --- a/doc/reference/json-glib-sections.txt +++ b/doc/reference/json-glib-sections.txt @@ -227,8 +227,8 @@ json_boxed_deserialize <SECTION> <FILE>json-gobject</FILE> <TITLE>GObject Serialization</TITLE> -json_gobject_new -json_gobject_dump +json_gobject_serialize +json_gobject_deserialize <SUBSECTION> json_construct_gobject 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 diff --git a/json-glib/json-gobject.h b/json-glib/json-gobject.h index a855fba..d294702 100644 --- a/json-glib/json-gobject.h +++ b/json-glib/json-gobject.h @@ -117,15 +117,15 @@ JsonNode *json_boxed_serialize (GType gboxed_t gpointer json_boxed_deserialize (GType gboxed_type, JsonNode *node); -GObject * json_gobject_new (GType gtype, - JsonObject *object); -JsonObject *json_gobject_dump (GObject *gobject); +JsonNode *json_gobject_serialize (GObject *gobject); +GObject * json_gobject_deserialize (GType gtype, + JsonNode *node); -GObject * json_construct_gobject (GType gtype, +GObject * json_construct_gobject (GType gtype, const gchar *data, gsize length, GError **error); -gchar * json_serialize_gobject (GObject *gobject, +gchar * json_serialize_gobject (GObject *gobject, gsize *length) G_GNUC_MALLOC; G_END_DECLS |