1 /* json-gobject.h - JSON GObject integration
3 * This file is part of JSON-GLib
4 * Copyright (C) 2007 OpenedHand Ltd.
5 * Copyright (C) 2009 Intel Corp.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 * Emmanuele Bassi <ebassi@linux.intel.com>
24 #ifndef __JSON_GOBJECT_H__
25 #define __JSON_GOBJECT_H__
27 #include <json-glib/json-types.h>
28 #include <glib-object.h>
32 #define JSON_TYPE_SERIALIZABLE (json_serializable_get_type ())
33 #define JSON_SERIALIZABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), JSON_TYPE_SERIALIZABLE, JsonSerializable))
34 #define JSON_IS_SERIALIZABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), JSON_TYPE_SERIALIZABLE))
35 #define JSON_SERIALIZABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), JSON_TYPE_SERIALIZABLE, JsonSerializableIface))
37 typedef struct _JsonSerializable JsonSerializable; /* dummy */
38 typedef struct _JsonSerializableIface JsonSerializableIface;
41 * JsonSerializableIface:
42 * @serialize_property: virtual function for serializing a #GObject property
44 * @deserialize_property: virtual function for deserializing a #JsonNode
45 * into a #GObject property
46 * @find_property: virtual function for finding a property definition using
48 * @list_properties: virtual function for listing the installed property
50 * @set_property: virtual function for setting a property
51 * @get_property: virtual function for getting a property
53 * Interface that allows serializing and deserializing #GObject<!-- -->s
54 * with properties storing complex data types. The json_serialize_gobject()
55 * function will check if the passed #GObject implements this interface,
56 * so it can also be used to override the default property serialization
59 struct _JsonSerializableIface
62 GTypeInterface g_iface;
65 JsonNode *(* serialize_property) (JsonSerializable *serializable,
66 const gchar *property_name,
69 gboolean (* deserialize_property) (JsonSerializable *serializable,
70 const gchar *property_name,
73 JsonNode *property_node);
75 GParamSpec * (* find_property) (JsonSerializable *serializable,
77 GParamSpec **(* list_properties) (JsonSerializable *serializable,
79 void (* set_property) (JsonSerializable *serializable,
82 void (* get_property) (JsonSerializable *serializable,
87 GType json_serializable_get_type (void) G_GNUC_CONST;
89 JsonNode *json_serializable_serialize_property (JsonSerializable *serializable,
90 const gchar *property_name,
93 gboolean json_serializable_deserialize_property (JsonSerializable *serializable,
94 const gchar *property_name,
97 JsonNode *property_node);
99 GParamSpec * json_serializable_find_property (JsonSerializable *serializable,
101 GParamSpec ** json_serializable_list_properties (JsonSerializable *serializable,
103 void json_serializable_set_property (JsonSerializable *serializable,
105 const GValue *value);
106 void json_serializable_get_property (JsonSerializable *serializable,
110 JsonNode *json_serializable_default_serialize_property (JsonSerializable *serializable,
111 const gchar *property_name,
114 gboolean json_serializable_default_deserialize_property (JsonSerializable *serializable,
115 const gchar *property_name,
118 JsonNode *property_node);
121 * JsonBoxedSerializeFunc:
124 * Serializes the passed #GBoxed and stores it inside a #JsonNode
126 * Return value: the newly created #JsonNode
130 typedef JsonNode *(* JsonBoxedSerializeFunc) (gconstpointer boxed);
133 * JsonBoxedDeserializeFunc:
136 * Deserializes the contents of the passed #JsonNode into a #GBoxed
138 * Return value: the newly created boxed type
142 typedef gpointer (* JsonBoxedDeserializeFunc) (JsonNode *node);
144 void json_boxed_register_serialize_func (GType gboxed_type,
145 JsonNodeType node_type,
146 JsonBoxedSerializeFunc serialize_func);
147 void json_boxed_register_deserialize_func (GType gboxed_type,
148 JsonNodeType node_type,
149 JsonBoxedDeserializeFunc deserialize_func);
150 gboolean json_boxed_can_serialize (GType gboxed_type,
151 JsonNodeType *node_type);
152 gboolean json_boxed_can_deserialize (GType gboxed_type,
153 JsonNodeType node_type);
154 JsonNode *json_boxed_serialize (GType gboxed_type,
155 gconstpointer boxed);
156 gpointer json_boxed_deserialize (GType gboxed_type,
159 JsonNode *json_gobject_serialize (GObject *gobject);
160 GObject * json_gobject_deserialize (GType gtype,
163 GObject * json_gobject_from_data (GType gtype,
167 gchar * json_gobject_to_data (GObject *gobject,
170 #ifndef JSON_DISABLE_DEPRECATED
171 GObject * json_construct_gobject (GType gtype,
174 GError **error) G_GNUC_DEPRECATED;
175 gchar * json_serialize_gobject (GObject *gobject,
176 gsize *length) G_GNUC_MALLOC G_GNUC_DEPRECATED;
177 #endif /* JSON_DISABLE_DEPRECATED */
182 #endif /* __JSON_GOBJECT_H__ */