json.serializable_mixin

Module for [Serializable] interface mixin

Templates 2

tmplSerializableT()

[json.serializable.Serializable] is an interface for controlling the serialization and deserialization of [gobject.object.ObjectWrap] classes.

Implementing this interface allows controlling how the class is going to be serialized or deserialized by func@Json.construct_gobject and func@Json.serialize_gobject, respectively.

Functions
bool defaultDeserializeProperty(string propertyName, gobject.value.Value value, gobject.param_spec.ParamSpec pspec, json.node.Node propertyNode)

Calls the default implementation of the vfuncJson.Serializable.deserialize_property virtual function.

This function can be used inside a custom implementation of the deserialize_property() virtual function in lieu of calling the default implementation through [gobject.global.typeDefaultInterfacePeek]:

JsonSerializable *iface;
gboolean res;

iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
res = iface->deserialize_property (serializable, property_name,
                                  value,
                                  pspec,
                                  property_node);

Parameters

propertyNamethe name of the property to deserialize
valuea pointer to an uninitialized value
pspeca property description
propertyNodethe JSON node containing the serialized property

Returns

TRUE if the property was successfully deserialized
json.node.Node defaultSerializeProperty(string propertyName, gobject.value.Value value, gobject.param_spec.ParamSpec pspec)

Calls the default implementation of the vfuncJson.Serializable.serialize_property virtual function.

This function can be used inside a custom implementation of the serialize_property() virtual function in lieu of calling the default implementation through [gobject.global.typeDefaultInterfacePeek]:

JsonSerializable *iface;
JsonNode *node;

iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
node = iface->serialize_property (serializable, property_name,
                                 value,
                                 pspec);

This function will return NULL if the property could not be serialized.

Parameters

propertyNamethe name of the property to serialize
valuethe value of the property to serialize
pspeca property description

Returns

a node containing the

serialized property

bool deserializeProperty(string propertyName, out gobject.value.Value value, gobject.param_spec.ParamSpec pspec, json.node.Node propertyNode)

Asks a [json.serializable.Serializable] implementation to deserialize the property contained inside property_node and place its value into value.

The value can be:

  • an empty [gobject.value.Value] initialized by G_VALUE_INIT, which will be automatically

initialized with the expected type of the property by using the given property description (since JSON-GLib 1.6)

  • a [gobject.value.Value] initialized with the expected type of the property

This function will not be called for properties that are marked as as G_PARAM_CONSTRUCT_ONLY.

Parameters

propertyNamethe name of the property to serialize
valuea pointer to an uninitialized value
pspeca property description
propertyNodethe JSON node containing the serialized property

Returns

TRUE if the property was successfully deserialized
gobject.param_spec.ParamSpec findProperty(string name)

Calls the vfuncJson.Serializable.find_property implementation on the [json.serializable.Serializable] instance, which will return the property description for the given name.

Parameters

namethe name of the property

Returns

the property description
void getProperty(gobject.param_spec.ParamSpec pspec, out gobject.value.Value value)

Calls the vfuncJson.Serializable.get_property implementation on the [json.serializable.Serializable] instance, which will get the value of the given property.

Parameters

pspeca property description
valuereturn location for the property value
gobject.param_spec.ParamSpec[] listProperties()

Calls the vfuncJson.Serializable.list_properties implementation on the [json.serializable.Serializable] instance, which will return the list of serializable properties.

Returns

the serializable

properties of the object

json.node.Node serializeProperty(string propertyName, gobject.value.Value value, gobject.param_spec.ParamSpec pspec)

Asks a [json.serializable.Serializable] implementation to serialize an object property into a JSON node.

Parameters

propertyNamethe name of the property to serialize
valuethe value of the property to serialize
pspeca property description

Returns

a node containing the serialized property
void setProperty(gobject.param_spec.ParamSpec pspec, gobject.value.Value value)

Calls the vfuncJson.Serializable.set_property implementation on the [json.serializable.Serializable] instance, which will set the property with the given value.

Parameters

pspeca property description
valuethe property value to set
tmplSerializableGidBuilderT()