Imported Upstream version 0.16.0
[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</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.78.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" class="variablelist">
84 <colgroup>
85 <col align="left" valign="top">
86 <col>
87 </colgroup>
88 <tbody>
89 <tr>
90 <td><p><span class="term"><em class="parameter"><code>gobject</code></em> :</span></p></td>
91 <td>a <span class="type">GObject</span>
92 </td>
93 </tr>
94 <tr>
95 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
96 <td>the newly created <a class="link" href="json-glib-JSON-Node.html#JsonNode" title="JsonNode"><span class="type">JsonNode</span></a>
97 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
98 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>
99 </td>
100 </tr>
101 </tbody>
102 </table></div>
103 <p class="since">Since 0.10</p>
104 </div>
105 <hr>
106 <div class="refsect2">
107 <a name="json-gobject-deserialize"></a><h3>json_gobject_deserialize ()</h3>
108 <pre class="programlisting"><span class="returnvalue">GObject</span> *           json_gobject_deserialize            (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
109                                                          <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>
110 <p>
111 Creates a new <span class="type">GObject</span> of type <em class="parameter"><code>gtype</code></em>, and constructs it
112 using the members of the passed <a class="link" href="json-glib-JSON-Object.html#JsonObject" title="JsonObject"><span class="type">JsonObject</span></a>
113 </p>
114 <div class="variablelist"><table border="0" class="variablelist">
115 <colgroup>
116 <col align="left" valign="top">
117 <col>
118 </colgroup>
119 <tbody>
120 <tr>
121 <td><p><span class="term"><em class="parameter"><code>gtype</code></em> :</span></p></td>
122 <td>the type of the <span class="type">GObject</span> to create</td>
123 </tr>
124 <tr>
125 <td><p><span class="term"><em class="parameter"><code>node</code></em> :</span></p></td>
126 <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
127 instance of type <em class="parameter"><code>gtype</code></em>
128 </td>
129 </tr>
130 <tr>
131 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
132 <td>The newly created <span class="type">GObject</span>
133 instance. Use <code class="function">g_object_unref()</code> to free the resources
134 allocated by this function. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
135 </td>
136 </tr>
137 </tbody>
138 </table></div>
139 <p class="since">Since 0.10</p>
140 </div>
141 <hr>
142 <div class="refsect2">
143 <a name="json-gobject-to-data"></a><h3>json_gobject_to_data ()</h3>
144 <pre class="programlisting"><span class="returnvalue">gchar</span> *             json_gobject_to_data                (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>,
145                                                          <em class="parameter"><code><span class="type">gsize</span> *length</code></em>);</pre>
146 <p>
147 Serializes a <span class="type">GObject</span> into a JSON data stream, iterating recursively
148 over each property.
149 </p>
150 <p>
151 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
152 be asked to serialize all its properties; otherwise, the default
153 implementation will be use to translate the compatible types into
154 JSON native types.
155 </p>
156 <div class="variablelist"><table border="0" class="variablelist">
157 <colgroup>
158 <col align="left" valign="top">
159 <col>
160 </colgroup>
161 <tbody>
162 <tr>
163 <td><p><span class="term"><em class="parameter"><code>gobject</code></em> :</span></p></td>
164 <td>a <span class="type">GObject</span>
165 </td>
166 </tr>
167 <tr>
168 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
169 <td>return value for the length of the buffer, or <code class="literal">NULL</code>. <span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>]</span>
170 </td>
171 </tr>
172 <tr>
173 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
174 <td>a JSON data stream representing the passed <span class="type">GObject</span>
175 </td>
176 </tr>
177 </tbody>
178 </table></div>
179 <p class="since">Since 0.10</p>
180 </div>
181 <hr>
182 <div class="refsect2">
183 <a name="json-gobject-from-data"></a><h3>json_gobject_from_data ()</h3>
184 <pre class="programlisting"><span class="returnvalue">GObject</span> *           json_gobject_from_data              (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
185                                                          <em class="parameter"><code>const <span class="type">gchar</span> *data</code></em>,
186                                                          <em class="parameter"><code><span class="type">gssize</span> length</code></em>,
187                                                          <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre>
188 <p>
189 Deserializes a JSON data stream and creates the corresponding
190 <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>
191 interface, it will be asked to deserialize all the JSON members
192 into the respective properties; otherwise, the default implementation
193 will be used to translate the compatible JSON native types.
194 </p>
195 <p>
196 Note: the JSON data stream must be an object declaration.
197 </p>
198 <div class="variablelist"><table border="0" class="variablelist">
199 <colgroup>
200 <col align="left" valign="top">
201 <col>
202 </colgroup>
203 <tbody>
204 <tr>
205 <td><p><span class="term"><em class="parameter"><code>gtype</code></em> :</span></p></td>
206 <td>the <span class="type">GType</span> of object to construct</td>
207 </tr>
208 <tr>
209 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
210 <td>a JSON data stream</td>
211 </tr>
212 <tr>
213 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
214 <td>length of the data stream, or -1 if it is NUL-terminated</td>
215 </tr>
216 <tr>
217 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
218 <td>return location for a <span class="type">GError</span>, or <code class="literal">NULL</code>
219 </td>
220 </tr>
221 <tr>
222 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
223 <td>a <span class="type">GObject</span> or <code class="literal">NULL</code>. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
224 </td>
225 </tr>
226 </tbody>
227 </table></div>
228 <p class="since">Since 0.10</p>
229 </div>
230 <hr>
231 <div class="refsect2">
232 <a name="json-construct-gobject"></a><h3>json_construct_gobject ()</h3>
233 <pre class="programlisting"><span class="returnvalue">GObject</span> *           json_construct_gobject              (<em class="parameter"><code><span class="type">GType</span> gtype</code></em>,
234                                                          <em class="parameter"><code>const <span class="type">gchar</span> *data</code></em>,
235                                                          <em class="parameter"><code><span class="type">gsize</span> length</code></em>,
236                                                          <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre>
237 <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
238 <h3 class="title">Warning</h3>
239 <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>
240 </div>
241 <p>
242 Deserializes a JSON data stream and creates the corresponding
243 <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>
244 interface, it will be asked to deserialize all the JSON members
245 into the respective properties; otherwise, the default implementation
246 will be used to translate the compatible JSON native types.
247 </p>
248 <p>
249 Note: the JSON data stream must be an object declaration.
250 </p>
251 <div class="variablelist"><table border="0" class="variablelist">
252 <colgroup>
253 <col align="left" valign="top">
254 <col>
255 </colgroup>
256 <tbody>
257 <tr>
258 <td><p><span class="term"><em class="parameter"><code>gtype</code></em> :</span></p></td>
259 <td>the <span class="type">GType</span> of object to construct</td>
260 </tr>
261 <tr>
262 <td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td>
263 <td>a JSON data stream</td>
264 </tr>
265 <tr>
266 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
267 <td>length of the data stream</td>
268 </tr>
269 <tr>
270 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
271 <td>return location for a <span class="type">GError</span>, or <code class="literal">NULL</code>
272 </td>
273 </tr>
274 <tr>
275 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
276 <td>a <span class="type">GObject</span> or <code class="literal">NULL</code>. <span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
277 </td>
278 </tr>
279 </tbody>
280 </table></div>
281 <p class="since">Since 0.4</p>
282 </div>
283 <hr>
284 <div class="refsect2">
285 <a name="json-serialize-gobject"></a><h3>json_serialize_gobject ()</h3>
286 <pre class="programlisting"><span class="returnvalue">gchar</span> *             json_serialize_gobject              (<em class="parameter"><code><span class="type">GObject</span> *gobject</code></em>,
287                                                          <em class="parameter"><code><span class="type">gsize</span> *length</code></em>);</pre>
288 <div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
289 <h3 class="title">Warning</h3>
290 <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>
291 </div>
292 <p>
293 Serializes a <span class="type">GObject</span> into a JSON data stream. If <em class="parameter"><code>gobject</code></em> implements
294 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
295 its properties; otherwise, the default implementation will be use to
296 translate the compatible types into JSON native types.
297 </p>
298 <div class="variablelist"><table border="0" class="variablelist">
299 <colgroup>
300 <col align="left" valign="top">
301 <col>
302 </colgroup>
303 <tbody>
304 <tr>
305 <td><p><span class="term"><em class="parameter"><code>gobject</code></em> :</span></p></td>
306 <td>a <span class="type">GObject</span>
307 </td>
308 </tr>
309 <tr>
310 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
311 <td>return value for the length of the buffer, or <code class="literal">NULL</code>. <span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>]</span>
312 </td>
313 </tr>
314 <tr>
315 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
316 <td>a JSON data stream representing the passed <span class="type">GObject</span>
317 </td>
318 </tr>
319 </tbody>
320 </table></div>
321 </div>
322 </div>
323 </div>
324 <div class="footer">
325 <hr>
326           Generated by GTK-Doc V1.18.1</div>
327 </body>
328 </html>