1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="json-glib-GObject-Serialization">
<refmeta>
<refentrytitle role="top_of_page" id="json-glib-GObject-Serialization.top_of_page">GObject Serialization</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>JSON-GLIB Library</refmiscinfo>
</refmeta>
<refnamediv>
<refname>GObject Serialization</refname>
<refpurpose>Serialize and deserialize GObjects</refpurpose>
</refnamediv>
<refsynopsisdiv id="json-glib-GObject-Serialization.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>
<synopsis>
<link linkend="JsonNode">JsonNode</link> * <link linkend="json-gobject-serialize">json_gobject_serialize</link> (<link linkend="GObject">GObject</link> *gobject);
<link linkend="GObject">GObject</link> * <link linkend="json-gobject-deserialize">json_gobject_deserialize</link> (<link linkend="GType">GType</link> gtype,
<link linkend="JsonNode">JsonNode</link> *node);
<link linkend="gchar">gchar</link> * <link linkend="json-gobject-to-data">json_gobject_to_data</link> (<link linkend="GObject">GObject</link> *gobject,
<link linkend="gsize">gsize</link> *length);
<link linkend="GObject">GObject</link> * <link linkend="json-gobject-from-data">json_gobject_from_data</link> (<link linkend="GType">GType</link> gtype,
const <link linkend="gchar">gchar</link> *data,
<link linkend="gssize">gssize</link> length,
<link linkend="GError">GError</link> **error);
<link linkend="GObject">GObject</link> * <link linkend="json-construct-gobject">json_construct_gobject</link> (<link linkend="GType">GType</link> gtype,
const <link linkend="gchar">gchar</link> *data,
<link linkend="gsize">gsize</link> length,
<link linkend="GError">GError</link> **error);
<link linkend="gchar">gchar</link> * <link linkend="json-serialize-gobject">json_serialize_gobject</link> (<link linkend="GObject">GObject</link> *gobject,
<link linkend="gsize">gsize</link> *length);
</synopsis>
</refsynopsisdiv>
<refsect1 id="json-glib-GObject-Serialization.description" role="desc">
<title role="desc.title">Description</title>
<para>
JSON-GLib provides API for serializing and deserializing <link linkend="GObject"><type>GObject</type></link><!-- -->s
to and from JSON data streams.
</para>
<para>
Simple <link linkend="GObject"><type>GObject</type></link> classes can be (de)serialized into JSON objects, if the
properties have compatible types with the native JSON types (integers,
booleans, strings, string vectors). If the class to be (de)serialized has
complex data types for properties (like boxed types or other objects)
then the class should implement the provided <link linkend="JsonSerializable"><type>JsonSerializable</type></link> interface
and its virtual functions.</para>
<para>
</para>
</refsect1>
<refsect1 id="json-glib-GObject-Serialization.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="json-gobject-serialize" role="function" condition="since:0.10">
<title>json_gobject_serialize ()</title>
<indexterm zone="json-gobject-serialize" role="0.10"><primary sortas="gobject_serialize">json_gobject_serialize</primary></indexterm><programlisting><link linkend="JsonNode">JsonNode</link> * json_gobject_serialize (<link linkend="GObject">GObject</link> *gobject);</programlisting>
<para>
Creates a <link linkend="JsonNode"><type>JsonNode</type></link> representing the passed <link linkend="GObject"><type>GObject</type></link>
instance. Each member of the returned JSON object will
map to a property of the <link linkend="GObject"><type>GObject</type></link></para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>gobject</parameter> :</term>
<listitem><simpara> a <link linkend="GObject"><type>GObject</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>transfer full. <acronym>transfer</acronym> full. </simpara></listitem></varlistentry>
</variablelist><para role="since">Since 0.10</para></refsect2>
<refsect2 id="json-gobject-deserialize" role="function" condition="since:0.10">
<title>json_gobject_deserialize ()</title>
<indexterm zone="json-gobject-deserialize" role="0.10"><primary sortas="gobject_deserialize">json_gobject_deserialize</primary></indexterm><programlisting><link linkend="GObject">GObject</link> * json_gobject_deserialize (<link linkend="GType">GType</link> gtype,
<link linkend="JsonNode">JsonNode</link> *node);</programlisting>
<para>
Creates a new <link linkend="GObject"><type>GObject</type></link> of type <parameter>gtype</parameter>, and constructs it
using the members of the passed <link linkend="JsonObject"><type>JsonObject</type></link></para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>gtype</parameter> :</term>
<listitem><simpara> the type of the <link linkend="GObject"><type>GObject</type></link> to create
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>node</parameter> :</term>
<listitem><simpara> a <link linkend="JsonNode"><type>JsonNode</type></link> of type <link linkend="JSON-NODE-OBJECT--CAPS"><literal>JSON_NODE_OBJECT</literal></link> describing the
instance of type <parameter>gtype</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara>transfer full. <acronym>transfer</acronym> full. </simpara></listitem></varlistentry>
</variablelist><para role="since">Since 0.10</para></refsect2>
<refsect2 id="json-gobject-to-data" role="function" condition="since:0.10">
<title>json_gobject_to_data ()</title>
<indexterm zone="json-gobject-to-data" role="0.10"><primary sortas="gobject_to_data">json_gobject_to_data</primary></indexterm><programlisting><link linkend="gchar">gchar</link> * json_gobject_to_data (<link linkend="GObject">GObject</link> *gobject,
<link linkend="gsize">gsize</link> *length);</programlisting>
<para>
Serializes a <link linkend="GObject"><type>GObject</type></link> into a JSON data stream, iterating recursively
over each property.
</para>
<para>
If <parameter>gobject</parameter> implements the <link linkend="JsonSerializableIface"><type>JsonSerializableIface</type></link> interface, it will
be asked to serialize all its properties; otherwise, the default
implementation will be use to translate the compatible types into
JSON native types.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>gobject</parameter> :</term>
<listitem><simpara> a <link linkend="GObject"><type>GObject</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>length</parameter> :</term>
<listitem><simpara> return value for the length of the buffer, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>. <acronym>out</acronym>. </simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a JSON data stream representing the passed <link linkend="GObject"><type>GObject</type></link>
</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 0.10</para></refsect2>
<refsect2 id="json-gobject-from-data" role="function" condition="since:0.10">
<title>json_gobject_from_data ()</title>
<indexterm zone="json-gobject-from-data" role="0.10"><primary sortas="gobject_from_data">json_gobject_from_data</primary></indexterm><programlisting><link linkend="GObject">GObject</link> * json_gobject_from_data (<link linkend="GType">GType</link> gtype,
const <link linkend="gchar">gchar</link> *data,
<link linkend="gssize">gssize</link> length,
<link linkend="GError">GError</link> **error);</programlisting>
<para>
Deserializes a JSON data stream and creates the corresponding
<link linkend="GObject"><type>GObject</type></link> class. If <parameter>gtype</parameter> implements the <link linkend="JsonSerializableIface"><type>JsonSerializableIface</type></link>
interface, it will be asked to deserialize all the JSON members
into the respective properties; otherwise, the default implementation
will be used to translate the compatible JSON native types.
</para>
<para>
Note: the JSON data stream must be an object declaration.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>gtype</parameter> :</term>
<listitem><simpara> the <link linkend="GType"><type>GType</type></link> of object to construct
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>data</parameter> :</term>
<listitem><simpara> a JSON data stream
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>length</parameter> :</term>
<listitem><simpara> length of the data stream, or -1 if it is NUL-terminated
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter> :</term>
<listitem><simpara> return location for a <link linkend="GError"><type>GError</type></link>, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a <link linkend="GObject"><type>GObject</type></link> or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 0.10</para></refsect2>
<refsect2 id="json-construct-gobject" role="function" condition="deprecated:0.10: Use json_gobject_from_data() instead|since:0.4">
<title>json_construct_gobject ()</title>
<indexterm zone="json-construct-gobject" role="deprecated"><primary sortas="construct_gobject">json_construct_gobject</primary></indexterm><indexterm zone="json-construct-gobject" role="0.4"><primary sortas="construct_gobject">json_construct_gobject</primary></indexterm><programlisting><link linkend="GObject">GObject</link> * json_construct_gobject (<link linkend="GType">GType</link> gtype,
const <link linkend="gchar">gchar</link> *data,
<link linkend="gsize">gsize</link> length,
<link linkend="GError">GError</link> **error);</programlisting>
<warning><para><literal>json_construct_gobject</literal> has been deprecated since version 0.10 and should not be used in newly-written code. Use <link linkend="json-gobject-from-data"><function>json_gobject_from_data()</function></link> instead</para></warning>
<para>
Deserializes a JSON data stream and creates the corresponding
<link linkend="GObject"><type>GObject</type></link> class. If <parameter>gtype</parameter> implements the <link linkend="JsonSerializableIface"><type>JsonSerializableIface</type></link>
interface, it will be asked to deserialize all the JSON members
into the respective properties; otherwise, the default implementation
will be used to translate the compatible JSON native types.
</para>
<para>
Note: the JSON data stream must be an object declaration.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>gtype</parameter> :</term>
<listitem><simpara> the <link linkend="GType"><type>GType</type></link> of object to construct
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>data</parameter> :</term>
<listitem><simpara> a JSON data stream
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>length</parameter> :</term>
<listitem><simpara> length of the data stream
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>error</parameter> :</term>
<listitem><simpara> return location for a <link linkend="GError"><type>GError</type></link>, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a <link linkend="GObject"><type>GObject</type></link> or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 0.4</para></refsect2>
<refsect2 id="json-serialize-gobject" role="function" condition="deprecated:0.10: Use json_gobject_to_data() instead">
<title>json_serialize_gobject ()</title>
<indexterm zone="json-serialize-gobject" role="deprecated"><primary sortas="serialize_gobject">json_serialize_gobject</primary></indexterm><programlisting><link linkend="gchar">gchar</link> * json_serialize_gobject (<link linkend="GObject">GObject</link> *gobject,
<link linkend="gsize">gsize</link> *length);</programlisting>
<warning><para><literal>json_serialize_gobject</literal> has been deprecated since version 0.10 and should not be used in newly-written code. Use <link linkend="json-gobject-to-data"><function>json_gobject_to_data()</function></link> instead</para></warning>
<para>
Serializes a <link linkend="GObject"><type>GObject</type></link> into a JSON data stream. If <parameter>gobject</parameter> implements
the <link linkend="JsonSerializableIface"><type>JsonSerializableIface</type></link> interface, it will be asked to serizalize all
its properties; otherwise, the default implementation will be use to
translate the compatible types into JSON native types.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>gobject</parameter> :</term>
<listitem><simpara> a <link linkend="GObject"><type>GObject</type></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>length</parameter> :</term>
<listitem><simpara> return value for the length of the buffer, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>. <acronym>out</acronym>. </simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a JSON data stream representing the passed <link linkend="GObject"><type>GObject</type></link>
</simpara></listitem></varlistentry>
</variablelist></refsect2>
</refsect1>
</refentry>
|