Imported Upstream version 1.2.4
[platform/upstream/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: JSON-GLib Reference Manual</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.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.25.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="5"><tr valign="middle">
16 <td width="100%" align="left" class="shortcuts">
17 <a href="#" class="shortcut">Top</a><span id="nav_description">  <span class="dim">|</span> 
18                   <a href="#json-glib-GObject-Serialization.description" class="shortcut">Description</a></span>
19 </td>
20 <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
21 <td><a accesskey="u" href="json-advanced.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
22 <td><a accesskey="p" href="json-advanced.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
23 <td><a accesskey="n" href="json-glib-Serializable-Interface.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
24 </tr></table>
25 <div class="refentry">
26 <a name="json-glib-GObject-Serialization"></a><div class="titlepage"></div>
27 <div class="refnamediv"><table width="100%"><tr>
28 <td valign="top">
29 <h2><span class="refentrytitle"><a name="json-glib-GObject-Serialization.top_of_page"></a>GObject Serialization</span></h2>
30 <p>GObject Serialization — Serialize and deserialize GObjects</p>
31 </td>
32 <td class="gallery_image" valign="top" align="right"></td>
33 </tr></table></div>
34 <div class="refsect1">
35 <a name="json-glib-GObject-Serialization.functions"></a><h2>Functions</h2>
36 <div class="informaltable"><table class="informaltable" width="100%" border="0">
37 <colgroup>
38 <col width="150px" class="functions_return">
39 <col class="functions_name">
40 </colgroup>
41 <tbody>
42 <tr>
43 <td class="function_type">
44 <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="returnvalue">JsonNode</span></a> *
45 </td>
46 <td class="function_name">
47 <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-serialize" title="json_gobject_serialize ()">json_gobject_serialize</a> <span class="c_punctuation">()</span>
48 </td>
49 </tr>
50 <tr>
51 <td class="function_type">
52 <span class="returnvalue">GObject</span> *
53 </td>
54 <td class="function_name">
55 <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-deserialize" title="json_gobject_deserialize ()">json_gobject_deserialize</a> <span class="c_punctuation">()</span>
56 </td>
57 </tr>
58 <tr>
59 <td class="function_type">
60 <span class="returnvalue">gchar</span> *
61 </td>
62 <td class="function_name">
63 <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-to-data" title="json_gobject_to_data ()">json_gobject_to_data</a> <span class="c_punctuation">()</span>
64 </td>
65 </tr>
66 <tr>
67 <td class="function_type">
68 <span class="returnvalue">GObject</span> *
69 </td>
70 <td class="function_name">
71 <a class="link" href="json-glib-GObject-Serialization.html#json-gobject-from-data" title="json_gobject_from_data ()">json_gobject_from_data</a> <span class="c_punctuation">()</span>
72 </td>
73 </tr>
74 <tr>
75 <td class="function_type">
76 <span class="returnvalue">GObject</span> *
77 </td>
78 <td class="function_name">
79 <a class="link" href="json-glib-GObject-Serialization.html#json-construct-gobject" title="json_construct_gobject ()">json_construct_gobject</a> <span class="c_punctuation">()</span>
80 </td>
81 </tr>
82 <tr>
83 <td class="function_type">
84 <span class="returnvalue">gchar</span> *
85 </td>
86 <td class="function_name">
87 <a class="link" href="json-glib-GObject-Serialization.html#json-serialize-gobject" title="json_serialize_gobject ()">json_serialize_gobject</a> <span class="c_punctuation">()</span>
88 </td>
89 </tr>
90 </tbody>
91 </table></div>
92 </div>
93 <div class="refsect1">
94 <a name="json-glib-GObject-Serialization.description"></a><h2>Description</h2>
95 <p>JSON-GLib provides API for serializing and deserializing <span class="type">GObject</span>
96 instances to and from JSON data streams.</p>
97 <p>Simple <span class="type">GObject</span> classes can be (de)serialized into JSON objects, if the
98 properties have compatible types with the native JSON types (integers,
99 booleans, strings, string vectors). If the class to be (de)serialized has
100 complex data types for properties (like boxed types or other objects)
101 then the class should implement the provided <a class="link" href="json-glib-Serializable-Interface.html#JsonSerializable"><span class="type">JsonSerializable</span></a> interface
102 and its virtual functions.</p>
103 </div>
104 <div class="refsect1">
105 <a name="json-glib-GObject-Serialization.functions_details"></a><h2>Functions</h2>
106 <div class="refsect2">
107 <a name="json-gobject-serialize"></a><h3>json_gobject_serialize ()</h3>
108 <pre class="programlisting"><a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="returnvalue">JsonNode</span></a> *
109 json_gobject_serialize (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>);</pre>
110 <p>Creates a <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a> representing the passed <span class="type">GObject</span>
111 instance. Each member of the returned JSON object will
112 map to a property of the <span class="type">GObject</span></p>
113 <div class="refsect3">
114 <a name="json-gobject-serialize.parameters"></a><h4>Parameters</h4>
115 <div class="informaltable"><table class="informaltable" width="100%" border="0">
116 <colgroup>
117 <col width="150px" class="parameters_name">
118 <col class="parameters_description">
119 <col width="200px" class="parameters_annotations">
120 </colgroup>
121 <tbody><tr>
122 <td class="parameter_name"><p>gobject</p></td>
123 <td class="parameter_description"><p>a <span class="type">GObject</span></p></td>
124 <td class="parameter_annotations"> </td>
125 </tr></tbody>
126 </table></div>
127 </div>
128 <div class="refsect3">
129 <a name="json-gobject-serialize.returns"></a><h4>Returns</h4>
130 <p> the newly created <a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a>
131 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-unref" title="json_node_unref ()"><code class="function">json_node_unref()</code></a> to free
132 the resources allocated by this function. </p>
133 <p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p>
134 </div>
135 <p class="since">Since: <a class="link" href="ix06.html#api-index-0.10">0.10</a></p>
136 </div>
137 <hr>
138 <div class="refsect2">
139 <a name="json-gobject-deserialize"></a><h3>json_gobject_deserialize ()</h3>
140 <pre class="programlisting"><span class="returnvalue">GObject</span> *
141 json_gobject_deserialize (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
142                           <em class="parameter"><code><a class="link" href="json-glib-JSON-Node.html#JsonNode"><span class="type">JsonNode</span></a> *node</code></em>);</pre>
143 <p>Creates a new <span class="type">GObject</span> of type <em class="parameter"><code>gtype</code></em>
144 , and constructs it
145 using the members of the passed <a class="link" href="json-glib-JSON-Object.html#JsonObject"><span class="type">JsonObject</span></a></p>
146 <div class="refsect3">
147 <a name="json-gobject-deserialize.parameters"></a><h4>Parameters</h4>
148 <div class="informaltable"><table class="informaltable" width="100%" border="0">
149 <colgroup>
150 <col width="150px" class="parameters_name">
151 <col class="parameters_description">
152 <col width="200px" class="parameters_annotations">
153 </colgroup>
154 <tbody>
155 <tr>
156 <td class="parameter_name"><p>gtype</p></td>
157 <td class="parameter_description"><p>the type of the <span class="type">GObject</span> to create</p></td>
158 <td class="parameter_annotations"> </td>
159 </tr>
160 <tr>
161 <td class="parameter_name"><p>node</p></td>
162 <td class="parameter_description"><p>a <a class="link" href="json-glib-JSON-Node.html#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
163 instance of type <em class="parameter"><code>gtype</code></em>
164 </p></td>
165 <td class="parameter_annotations"> </td>
166 </tr>
167 </tbody>
168 </table></div>
169 </div>
170 <div class="refsect3">
171 <a name="json-gobject-deserialize.returns"></a><h4>Returns</h4>
172 <p> The newly created <span class="type">GObject</span>
173 instance. Use <code class="function">g_object_unref()</code> to free the resources
174 allocated by this function. </p>
175 <p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p>
176 </div>
177 <p class="since">Since: <a class="link" href="ix06.html#api-index-0.10">0.10</a></p>
178 </div>
179 <hr>
180 <div class="refsect2">
181 <a name="json-gobject-to-data"></a><h3>json_gobject_to_data ()</h3>
182 <pre class="programlisting"><span class="returnvalue">gchar</span> *
183 json_gobject_to_data (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>,
184                       <em class="parameter"><code><span class="type">gsize</span> *length</code></em>);</pre>
185 <p>Serializes a <span class="type">GObject</span> into a JSON data stream, iterating recursively
186 over each property.</p>
187 <p>If <em class="parameter"><code>gobject</code></em>
188  implements the <a class="link" href="json-glib-Serializable-Interface.html#JsonSerializableIface" title="struct JsonSerializableIface"><span class="type">JsonSerializableIface</span></a> interface, it will
189 be asked to serialize all its properties; otherwise, the default
190 implementation will be use to translate the compatible types into
191 JSON native types.</p>
192 <div class="refsect3">
193 <a name="json-gobject-to-data.parameters"></a><h4>Parameters</h4>
194 <div class="informaltable"><table class="informaltable" width="100%" border="0">
195 <colgroup>
196 <col width="150px" class="parameters_name">
197 <col class="parameters_description">
198 <col width="200px" class="parameters_annotations">
199 </colgroup>
200 <tbody>
201 <tr>
202 <td class="parameter_name"><p>gobject</p></td>
203 <td class="parameter_description"><p>a <span class="type">GObject</span></p></td>
204 <td class="parameter_annotations"> </td>
205 </tr>
206 <tr>
207 <td class="parameter_name"><p>length</p></td>
208 <td class="parameter_description"><p> return value for the length of the buffer, or <code class="literal">NULL</code>. </p></td>
209 <td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>]</span></td>
210 </tr>
211 </tbody>
212 </table></div>
213 </div>
214 <div class="refsect3">
215 <a name="json-gobject-to-data.returns"></a><h4>Returns</h4>
216 <p> a JSON data stream representing the passed <span class="type">GObject</span></p>
217 </div>
218 <p class="since">Since: <a class="link" href="ix06.html#api-index-0.10">0.10</a></p>
219 </div>
220 <hr>
221 <div class="refsect2">
222 <a name="json-gobject-from-data"></a><h3>json_gobject_from_data ()</h3>
223 <pre class="programlisting"><span class="returnvalue">GObject</span> *
224 json_gobject_from_data (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
225                         <em class="parameter"><code>const <span class="type">gchar</span> *data</code></em>,
226                         <em class="parameter"><code><span class="type">gssize</span> length</code></em>,
227                         <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre>
228 <p>Deserializes a JSON data stream and creates the corresponding
229 <span class="type">GObject</span> class. If <em class="parameter"><code>gtype</code></em>
230  implements the <a class="link" href="json-glib-Serializable-Interface.html#JsonSerializableIface" title="struct JsonSerializableIface"><span class="type">JsonSerializableIface</span></a>
231 interface, it will be asked to deserialize all the JSON members
232 into the respective properties; otherwise, the default implementation
233 will be used to translate the compatible JSON native types.</p>
234 <p>Note: the JSON data stream must be an object declaration.</p>
235 <div class="refsect3">
236 <a name="json-gobject-from-data.parameters"></a><h4>Parameters</h4>
237 <div class="informaltable"><table class="informaltable" width="100%" border="0">
238 <colgroup>
239 <col width="150px" class="parameters_name">
240 <col class="parameters_description">
241 <col width="200px" class="parameters_annotations">
242 </colgroup>
243 <tbody>
244 <tr>
245 <td class="parameter_name"><p>gtype</p></td>
246 <td class="parameter_description"><p>the <span class="type">GType</span> of object to construct</p></td>
247 <td class="parameter_annotations"> </td>
248 </tr>
249 <tr>
250 <td class="parameter_name"><p>data</p></td>
251 <td class="parameter_description"><p>a JSON data stream</p></td>
252 <td class="parameter_annotations"> </td>
253 </tr>
254 <tr>
255 <td class="parameter_name"><p>length</p></td>
256 <td class="parameter_description"><p>length of the data stream, or -1 if it is NUL-terminated</p></td>
257 <td class="parameter_annotations"> </td>
258 </tr>
259 <tr>
260 <td class="parameter_name"><p>error</p></td>
261 <td class="parameter_description"><p>return location for a <span class="type">GError</span>, or <code class="literal">NULL</code></p></td>
262 <td class="parameter_annotations"> </td>
263 </tr>
264 </tbody>
265 </table></div>
266 </div>
267 <div class="refsect3">
268 <a name="json-gobject-from-data.returns"></a><h4>Returns</h4>
269 <p> a <span class="type">GObject</span> or <code class="literal">NULL</code>. </p>
270 <p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p>
271 </div>
272 <p class="since">Since: <a class="link" href="ix06.html#api-index-0.10">0.10</a></p>
273 </div>
274 <hr>
275 <div class="refsect2">
276 <a name="json-construct-gobject"></a><h3>json_construct_gobject ()</h3>
277 <pre class="programlisting"><span class="returnvalue">GObject</span> *
278 json_construct_gobject (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
279                         <em class="parameter"><code>const <span class="type">gchar</span> *data</code></em>,
280                         <em class="parameter"><code><span class="type">gsize</span> length</code></em>,
281                         <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre>
282 <div class="warning">
283 <p><code class="literal">json_construct_gobject</code> has been deprecated since version 0.10 and should not be used in newly-written code.</p>
284 <p>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>
285 </div>
286 <p>Deserializes a JSON data stream and creates the corresponding
287 <span class="type">GObject</span> class. If <em class="parameter"><code>gtype</code></em>
288  implements the <a class="link" href="json-glib-Serializable-Interface.html#JsonSerializableIface" title="struct JsonSerializableIface"><span class="type">JsonSerializableIface</span></a>
289 interface, it will be asked to deserialize all the JSON members
290 into the respective properties; otherwise, the default implementation
291 will be used to translate the compatible JSON native types.</p>
292 <p>Note: the JSON data stream must be an object declaration.</p>
293 <div class="refsect3">
294 <a name="json-construct-gobject.parameters"></a><h4>Parameters</h4>
295 <div class="informaltable"><table class="informaltable" width="100%" border="0">
296 <colgroup>
297 <col width="150px" class="parameters_name">
298 <col class="parameters_description">
299 <col width="200px" class="parameters_annotations">
300 </colgroup>
301 <tbody>
302 <tr>
303 <td class="parameter_name"><p>gtype</p></td>
304 <td class="parameter_description"><p>the <span class="type">GType</span> of object to construct</p></td>
305 <td class="parameter_annotations"> </td>
306 </tr>
307 <tr>
308 <td class="parameter_name"><p>data</p></td>
309 <td class="parameter_description"><p>a JSON data stream</p></td>
310 <td class="parameter_annotations"> </td>
311 </tr>
312 <tr>
313 <td class="parameter_name"><p>length</p></td>
314 <td class="parameter_description"><p>length of the data stream</p></td>
315 <td class="parameter_annotations"> </td>
316 </tr>
317 <tr>
318 <td class="parameter_name"><p>error</p></td>
319 <td class="parameter_description"><p>return location for a <span class="type">GError</span>, or <code class="literal">NULL</code></p></td>
320 <td class="parameter_annotations"> </td>
321 </tr>
322 </tbody>
323 </table></div>
324 </div>
325 <div class="refsect3">
326 <a name="json-construct-gobject.returns"></a><h4>Returns</h4>
327 <p> a <span class="type">GObject</span> or <code class="literal">NULL</code>. </p>
328 <p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p>
329 </div>
330 <p class="since">Since: <a class="link" href="ix03.html#api-index-0.4">0.4</a></p>
331 </div>
332 <hr>
333 <div class="refsect2">
334 <a name="json-serialize-gobject"></a><h3>json_serialize_gobject ()</h3>
335 <pre class="programlisting"><span class="returnvalue">gchar</span> *
336 json_serialize_gobject (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>,
337                         <em class="parameter"><code><span class="type">gsize</span> *length</code></em>);</pre>
338 <div class="warning">
339 <p><code class="literal">json_serialize_gobject</code> has been deprecated since version 0.10 and should not be used in newly-written code.</p>
340 <p>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>
341 </div>
342 <p>Serializes a <span class="type">GObject</span> into a JSON data stream. If <em class="parameter"><code>gobject</code></em>
343  implements
344 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
345 its properties; otherwise, the default implementation will be use to
346 translate the compatible types into JSON native types.</p>
347 <div class="refsect3">
348 <a name="json-serialize-gobject.parameters"></a><h4>Parameters</h4>
349 <div class="informaltable"><table class="informaltable" width="100%" border="0">
350 <colgroup>
351 <col width="150px" class="parameters_name">
352 <col class="parameters_description">
353 <col width="200px" class="parameters_annotations">
354 </colgroup>
355 <tbody>
356 <tr>
357 <td class="parameter_name"><p>gobject</p></td>
358 <td class="parameter_description"><p>a <span class="type">GObject</span></p></td>
359 <td class="parameter_annotations"> </td>
360 </tr>
361 <tr>
362 <td class="parameter_name"><p>length</p></td>
363 <td class="parameter_description"><p> return value for the length of the buffer, or <code class="literal">NULL</code>. </p></td>
364 <td class="parameter_annotations"><span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>]</span></td>
365 </tr>
366 </tbody>
367 </table></div>
368 </div>
369 <div class="refsect3">
370 <a name="json-serialize-gobject.returns"></a><h4>Returns</h4>
371 <p> a JSON data stream representing the passed <span class="type">GObject</span></p>
372 </div>
373 </div>
374 </div>
375 <div class="refsect1">
376 <a name="json-glib-GObject-Serialization.other_details"></a><h2>Types and Values</h2>
377 </div>
378 </div>
379 <div class="footer">
380 <hr>Generated by GTK-Doc V1.25.1</div>
381 </body>
382 </html>