![]() |
![]() |
![]() |
JSON-GLib 0.6.2 Reference Manual | ![]() |
---|---|---|---|---|
JsonSerializableIface; JsonNode* json_serializable_serialize_property (JsonSerializable *serializable, const gchar *property_name, const GValue *value, GParamSpec *pspec); gboolean json_serializable_deserialize_property (JsonSerializable *serializable, const gchar *property_name, GValue *value, GParamSpec *pspec, JsonNode *property_node); gchar* json_serialize_gobject (GObject *gobject, gsize *length); GObject* json_construct_gobject (GType gtype, const gchar *data, gsize length, GError **error);
JSON-GLib provides API for serializing and deserializing GObjects to and from JSON data streams.
Simple GObject 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 JsonSerializable interface and its virtual functions.
typedef struct { JsonNode *(* serialize_property) (JsonSerializable *serializable, const gchar *property_name, const GValue *value, GParamSpec *pspec); gboolean (* deserialize_property) (JsonSerializable *serializable, const gchar *property_name, GValue *value, GParamSpec *pspec, JsonNode *property_node); } JsonSerializableIface;
Interface that allows serializing and deserializing GObjects
with properties storing complex data types. The json_serialize_gobject()
function will check if the passed GObject implements this interface,
so it can also be used to override the default property serialization
sequence.
JsonNode* json_serializable_serialize_property (JsonSerializable *serializable, const gchar *property_name, const GValue *value, GParamSpec *pspec);
Asks a JsonSerializable implementation to serialize a GObject property into a JsonNode object.
|
a JsonSerializable object |
|
the name of the property |
|
the value of the property |
|
a GParamSpec |
Returns : |
a JsonNode containing the serialize property |
gboolean json_serializable_deserialize_property (JsonSerializable *serializable, const gchar *property_name, GValue *value, GParamSpec *pspec, JsonNode *property_node);
Asks a JsonSerializable implementation to deserialize the
property contained inside property_node
into value
.
|
a JsonSerializable |
|
the name of the property |
|
a pointer to an uninitialized GValue |
|
a GParamSpec |
|
a JsonNode containing the serialized property |
Returns : |
TRUE if the property was successfully deserialized.
|
gchar* json_serialize_gobject (GObject *gobject, gsize *length);
Serializes a GObject into a JSON data stream. If gobject
implements
the JsonSerializableIface 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.
|
a GObject |
|
return value for the length of the buffer, or NULL
|
Returns : |
a JSON data stream representing the passed GObject |
GObject* json_construct_gobject (GType gtype, const gchar *data, gsize length, GError **error);
Deserializes a JSON data stream and creates the corresponding
GObject class. If gtype
implements the JsonSerializableIface
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.
Note: the JSON data stream must be an object declaration.
|
the GType of object to construct |
|
a JSON data stream |
|
length of the data stream, or -1 if it is NUL-terminated |
|
return location for a GError, or NULL
|
Returns : |
a GObject or NULL
|
Since 0.4