Initial Import
[profile/ivi/json-glib.git] / doc / reference / html / json-glib-GObject-Serialization.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>GObject Serialization</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="JSON-GLib Reference Manual">
8 <link rel="up" href="json-advanced.html" title="Part IV. JSON-GLib Advanced API">
9 <link rel="prev" href="json-advanced.html" title="Part IV. JSON-GLib Advanced API">
10 <link rel="next" href="json-glib-Serializable-Interface.html" title="Serializable Interface">
11 <meta name="generator" content="GTK-Doc V1.18.1 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
16 <tr valign="middle">
17 <td><a accesskey="p" href="json-advanced.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18 <td><a accesskey="u" href="json-advanced.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20 <th width="100%" align="center">JSON-GLib Reference Manual</th>
21 <td><a accesskey="n" href="json-glib-Serializable-Interface.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
22 </tr>
23 <tr><td colspan="5" class="shortcuts">
24 <a href="#json-glib-GObject-Serialization.synopsis" class="shortcut">Top</a>
25                    | 
26                   <a href="#json-glib-GObject-Serialization.description" class="shortcut">Description</a>
27 </td></tr>
28 </table>
29 <div class="refentry">
30 <a name="json-glib-GObject-Serialization"></a><div class="titlepage"></div>
31 <div class="refnamediv"><table width="100%"><tr>
32 <td valign="top">
33 <h2><span class="refentrytitle"><a name="json-glib-GObject-Serialization.top_of_page"></a>GObject Serialization</span></h2>
34 <p>GObject Serialization — Serialize and deserialize GObjects</p>
35 </td>
36 <td valign="top" align="right"></td>
37 </tr></table></div>
38 <div class="refsynopsisdiv">
39 <a name="json-glib-GObject-Serialization.synopsis"></a><h2>Synopsis</h2>
40 <pre class="synopsis"><a class="link" href="json-glib-JSON-Node.html#JsonNode" title="JsonNode"><span class="returnvalue">JsonNode</span></a> *          <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-serialize" title="json_gobject_serialize ()">json_gobject_serialize</a>              (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>);
41 <span class="returnvalue">GObject</span> *           <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-deserialize" title="json_gobject_deserialize ()">json_gobject_deserialize</a>            (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
42                                                          <em class="parameter"><code><a class="link" href="json-glib-JSON-Node.html#JsonNode" title="JsonNode"><span class="type">JsonNode</span></a> *node</code></em>);
43 <span class="returnvalue">gchar</span> *             <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-to-data" title="json_gobject_to_data ()">json_gobject_to_data</a>                (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>,
44                                                          <em class="parameter"><code><span class="type">gsize</span> *length</code></em>);
45 <span class="returnvalue">GObject</span> *           <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-from-data" title="json_gobject_from_data ()">json_gobject_from_data</a>              (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
46                                                          <em class="parameter"><code>const <span class="type">gchar</span> *data</code></em>,
47                                                          <em class="parameter"><code><span class="type">gssize</span> length</code></em>,
48                                                          <em class="parameter"><code><span class="type">GError</span> **error</code></em>);
49
50 <span class="returnvalue">GObject</span> *           <a class="link" href="json-glib-GObject-Serialization.html#json-construct-gobject" title="json_construct_gobject ()">json_construct_gobject</a>              (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
51                                                          <em class="parameter"><code>const <span class="type">gchar</span> *data</code></em>,
52                                                          <em class="parameter"><code><span class="type">gsize</span> length</code></em>,
53                                                          <em class="parameter"><code><span class="type">GError</span> **error</code></em>);
54 <span class="returnvalue">gchar</span> *             <a class="link" href="json-glib-GObject-Serialization.html#json-serialize-gobject" title="json_serialize_gobject ()">json_serialize_gobject</a>              (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>,
55                                                          <em class="parameter"><code><span class="type">gsize</span> *length</code></em>);
56 </pre>
57 </div>
58 <div class="refsect1">
59 <a name="json-glib-GObject-Serialization.description"></a><h2>Description</h2>
60 <p>
61 JSON-GLib provides API for serializing and deserializing <span class="type">GObject</span>s
62 to and from JSON data streams.
63 </p>
64 <p>
65 Simple <span class="type">GObject</span> classes can be (de)serialized into JSON objects, if the
66 properties have compatible types with the native JSON types (integers,
67 booleans, strings, string vectors). If the class to be (de)serialized has
68 complex data types for properties (like boxed types or other objects)
69 then the class should implement the provided <span class="type">JsonSerializable</span> interface
70 and its virtual functions.
71 </p>
72 </div>
73 <div class="refsect1">
74 <a name="json-glib-GObject-Serialization.details"></a><h2>Details</h2>
75 <div class="refsect2">
76 <a name="json-gobject-serialize"></a><h3>json_gobject_serialize ()</h3>
77 <pre class="programlisting"><a class="link" href="json-glib-JSON-Node.html#JsonNode" title="JsonNode"><span class="returnvalue">JsonNode</span></a> *          json_gobject_serialize              (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>);</pre>
78 <p>
79 Creates a <a class="link" href="json-glib-JSON-Node.html#JsonNode" title="JsonNode"><span class="type">JsonNode</span></a> representing the passed <span class="type">GObject</span>
80 instance. Each member of the returned JSON object will
81 map to a property of the <span class="type">GObject</span>
82 </p>
83 <div class="variablelist"><table border="0">
84 <col align="left" valign="top">
85 <tbody>
86 <tr>
87 <td><p><span class="term"><em class="parameter"><code>gobject</code></em> :</span></p></td>
88 <td>a <span class="type">GObject</span>
89 </td>
90 </tr>
91 <tr>
92 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
93 <td>the newly created <a class="link" href="json-glib-JSON-Node.html#JsonNode" title="JsonNode"><span class="type">JsonNode</span></a>
94 of type <a class="link" href="json-glib-JSON-Node.html#JSON-NODE-OBJECT:CAPS"><code class="literal">JSON_NODE_OBJECT</code></a>. Use <a class="link" href="json-glib-JSON-Node.html#json-node-free" title="json_node_free ()"><code class="function">json_node_free()</code></a> to free
95 the resources allocated by this function. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
96 </td>
97 </tr>
98 </tbody>
99 </table></div>
100 <p class="since">Since 0.10</p>
101 </div>
102 <hr>
103 <div class="refsect2">
104 <a name="json-gobject-deserialize"></a><h3>json_gobject_deserialize ()</h3>
105 <pre class="programlisting"><span class="returnvalue">GObject</span> *           json_gobject_deserialize            (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
106                                                          <em class="parameter"><code><a class="link" href="json-glib-JSON-Node.html#JsonNode" title="JsonNode"><span class="type">JsonNode</span></a> *node</code></em>);</pre>
107 <p>
108 Creates a new <span class="type">GObject</span> of type <em class="parameter"><code>gtype</code></em>, and constructs it
109 using the members of the passed <a class="link" href="json-glib-JSON-Object.html#JsonObject" title="JsonObject"><span class="type">JsonObject</span></a>
110 </p>
111 <div class="variablelist"><table border="0">
112 <col align="left" valign="top">
113 <tbody>
114 <tr>
115 <td><p><span class="term"><em class="parameter"><code>gtype</code></em> :</span></p></td>
116 <td>the type of the <span class="type">GObject</span> to create</td>
117 </tr>
118 <tr>
119 <td><p><span class="term"><em class="parameter"><code>node</code></em> :</span></p></td>
120 <td>a <a class="link" href="json-glib-JSON-Node.html#JsonNode" title="JsonNode"><span class="type">JsonNode</span></a> of type <a class="link" href="json-glib-JSON-Node.html#JSON-NODE-OBJECT:CAPS"><code class="literal">JSON_NODE_OBJECT</code></a> describing the
121 instance of type <em class="parameter"><code>gtype</code></em>
122 </td>
123 </tr>
124 <tr>
125 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
126 <td>The newly created <span class="type">GObject</span>
127 instance. Use <code class="function">g_object_unref()</code> to free the resources
128 allocated by this function. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
129 </td>
130 </tr>
131 </tbody>
132 </table></div>
133 <p class="since">Since 0.10</p>
134 </div>
135 <hr>
136 <div class="refsect2">
137 <a name="json-gobject-to-data"></a><h3>json_gobject_to_data ()</h3>
138 <pre class="programlisting"><span class="returnvalue">gchar</span> *             json_gobject_to_data                (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>,
139                                                          <em class="parameter"><code><span class="type">gsize</span> *length</code></em>);</pre>
140 <p>
141 Serializes a <span class="type">GObject</span> into a JSON data stream, iterating recursively
142 over each property.
143 </p>
144 <p>
145 If <em class="parameter"><code>gobject</code></em> implements the <a class="link" href="json-glib-Serializable-Interface.html#JsonSerializableIface" title="struct JsonSerializableIface"><span class="type">JsonSerializableIface</span></a> interface, it will
146 be asked to serialize all its properties; otherwise, the default
147 implementation will be use to translate the compatible types into
148 JSON native types.
149 </p>
150 <div class="variablelist"><table border="0">
151 <col align="left" valign="top">
152 <tbody>
153 <tr>
154 <td><p><span class="term"><em class="parameter"><code>gobject</code></em> :</span></p></td>
155 <td>a <span class="type">GObject</span>
156 </td>
157 </tr>
158 <tr>
159 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
160 <td>return value for the length of the buffer, or <a href="/home/ebassi/gnome3/install/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL--CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>]</span>
161 </td>
162 </tr>
163 <tr>
164 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
165 <td>a JSON data stream representing the passed <span class="type">GObject</span>
166 </td>
167 </tr>
168 </tbody>
169 </table></div>
170 <p class="since">Since 0.10</p>
171 </div>
172 <hr>
173 <div class="refsect2">
174 <a name="json-gobject-from-data"></a><h3>json_gobject_from_data ()</h3>
175 <pre class="programlisting"><span class="returnvalue">GObject</span> *           json_gobject_from_data              (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
176                                                          <em class="parameter"><code>const <span class="type">gchar</span> *data</code></em>,
177                                                          <em class="parameter"><code><span class="type">gssize</span> length</code></em>,
178                                                          <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre>
179 <p>
180 Deserializes a JSON data stream and creates the corresponding
181 <span class="type">GObject</span> class. If <em class="parameter"><code>gtype</code></em> implements the <a class="link" href="json-glib-Serializable-Interface.html#JsonSerializableIface" title="struct JsonSerializableIface"><span class="type">JsonSerializableIface</span></a>
182 interface, it will be asked to deserialize all the JSON members
183 into the respective properties; otherwise, the default implementation
184 will be used to translate the compatible JSON native types.
185 </p>
186 <p>
187 Note: the JSON data stream must be an object declaration.
188 </p>
189 <div class="variablelist"><table border="0">
190 <col align="left" valign="top">
191 <tbody>
192 <tr>
193 <td><p><span class="term"><em class="parameter"><code>gtype</code></em> :</span></p></td>
194 <td>the <span class="type">GType</span> of object to construct</td>
195 </tr>
196 <tr>
197 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
198 <td>a JSON data stream</td>
199 </tr>
200 <tr>
201 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
202 <td>length of the data stream, or -1 if it is NUL-terminated</td>
203 </tr>
204 <tr>
205 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
206 <td>return location for a <span class="type">GError</span>, or <a href="/home/ebassi/gnome3/install/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL--CAPS"><code class="literal">NULL</code></a>
207 </td>
208 </tr>
209 <tr>
210 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
211 <td>a <span class="type">GObject</span> or <a href="/home/ebassi/gnome3/install/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL--CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
212 </td>
213 </tr>
214 </tbody>
215 </table></div>
216 <p class="since">Since 0.10</p>
217 </div>
218 <hr>
219 <div class="refsect2">
220 <a name="json-construct-gobject"></a><h3>json_construct_gobject ()</h3>
221 <pre class="programlisting"><span class="returnvalue">GObject</span> *           json_construct_gobject              (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
222                                                          <em class="parameter"><code>const <span class="type">gchar</span> *data</code></em>,
223                                                          <em class="parameter"><code><span class="type">gsize</span> length</code></em>,
224                                                          <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre>
225 <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
226 <h3 class="title">Warning</h3>
227 <p><code class="literal">json_construct_gobject</code> has been deprecated since version 0.10 and should not be used in newly-written code. Use <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-from-data" title="json_gobject_from_data ()"><code class="function">json_gobject_from_data()</code></a> instead</p>
228 </div>
229 <p>
230 Deserializes a JSON data stream and creates the corresponding
231 <span class="type">GObject</span> class. If <em class="parameter"><code>gtype</code></em> implements the <a class="link" href="json-glib-Serializable-Interface.html#JsonSerializableIface" title="struct JsonSerializableIface"><span class="type">JsonSerializableIface</span></a>
232 interface, it will be asked to deserialize all the JSON members
233 into the respective properties; otherwise, the default implementation
234 will be used to translate the compatible JSON native types.
235 </p>
236 <p>
237 Note: the JSON data stream must be an object declaration.
238 </p>
239 <div class="variablelist"><table border="0">
240 <col align="left" valign="top">
241 <tbody>
242 <tr>
243 <td><p><span class="term"><em class="parameter"><code>gtype</code></em> :</span></p></td>
244 <td>the <span class="type">GType</span> of object to construct</td>
245 </tr>
246 <tr>
247 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
248 <td>a JSON data stream</td>
249 </tr>
250 <tr>
251 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
252 <td>length of the data stream</td>
253 </tr>
254 <tr>
255 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
256 <td>return location for a <span class="type">GError</span>, or <a href="/home/ebassi/gnome3/install/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL--CAPS"><code class="literal">NULL</code></a>
257 </td>
258 </tr>
259 <tr>
260 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
261 <td>a <span class="type">GObject</span> or <a href="/home/ebassi/gnome3/install/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL--CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
262 </td>
263 </tr>
264 </tbody>
265 </table></div>
266 <p class="since">Since 0.4</p>
267 </div>
268 <hr>
269 <div class="refsect2">
270 <a name="json-serialize-gobject"></a><h3>json_serialize_gobject ()</h3>
271 <pre class="programlisting"><span class="returnvalue">gchar</span> *             json_serialize_gobject              (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>,
272                                                          <em class="parameter"><code><span class="type">gsize</span> *length</code></em>);</pre>
273 <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
274 <h3 class="title">Warning</h3>
275 <p><code class="literal">json_serialize_gobject</code> has been deprecated since version 0.10 and should not be used in newly-written code. Use <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-to-data" title="json_gobject_to_data ()"><code class="function">json_gobject_to_data()</code></a> instead</p>
276 </div>
277 <p>
278 Serializes a <span class="type">GObject</span> into a JSON data stream. If <em class="parameter"><code>gobject</code></em> implements
279 the <a class="link" href="json-glib-Serializable-Interface.html#JsonSerializableIface" title="struct JsonSerializableIface"><span class="type">JsonSerializableIface</span></a> interface, it will be asked to serizalize all
280 its properties; otherwise, the default implementation will be use to
281 translate the compatible types into JSON native types.
282 </p>
283 <div class="variablelist"><table border="0">
284 <col align="left" valign="top">
285 <tbody>
286 <tr>
287 <td><p><span class="term"><em class="parameter"><code>gobject</code></em> :</span></p></td>
288 <td>a <span class="type">GObject</span>
289 </td>
290 </tr>
291 <tr>
292 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
293 <td>return value for the length of the buffer, or <a href="/home/ebassi/gnome3/install/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL--CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>]</span>
294 </td>
295 </tr>
296 <tr>
297 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
298 <td>a JSON data stream representing the passed <span class="type">GObject</span>
299 </td>
300 </tr>
301 </tbody>
302 </table></div>
303 </div>
304 </div>
305 </div>
306 <div class="footer">
307 <hr>
308           Generated by GTK-Doc V1.18.1</div>
309 </body>
310 </html>