manpagez: man pages & more
html files: json-glib
Home | html | info | man

Serializable Interface

Serializable Interface — Interface for serialize and deserialize special GObjects

Types and Values

Object Hierarchy

    GInterface
    ╰── JsonSerializable

Includes

#include <json-glib/json-glib.h>

Description

JsonSerializable is an interface for GObject classes that allows controlling how the class is going to be serialized or deserialized by json_construct_gobject() and json_serialize_gobject() respectively.

Functions

json_serializable_serialize_property ()

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.

Parameters

serializable

a JsonSerializable object

 

property_name

the name of the property

 

value

the value of the property

 

pspec

a GParamSpec

 

Returns

a JsonNode containing the serialized property


json_serializable_deserialize_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 .

Parameters

serializable

a JsonSerializable

 

property_name

the name of the property

 

value

a pointer to an uninitialized GValue.

[out]

pspec

a GParamSpec

 

property_node

a JsonNode containing the serialized property

 

Returns

TRUE if the property was successfully deserialized.


json_serializable_find_property ()

GParamSpec *
json_serializable_find_property (JsonSerializable *serializable,
                                 const char *name);

Calls the JsonSerializableIface.find_property() implementation on the serializable instance. *

Parameters

serializable

a JsonSerializable

 

name

the name of the property

 

Returns

the GParamSpec for the property or NULL if no property was found.

[transfer none]

Since: 0.14


json_serializable_get_property ()

void
json_serializable_get_property (JsonSerializable *serializable,
                                GParamSpec *pspec,
                                GValue *value);

Calls the JsonSerializableIface.get_property() implementation on the serializable instance.

Parameters

serializable

a JsonSerializable

 

pspec

a GParamSpec

 

value

return location for the property value.

[out]

Since: 0.14


json_serializable_list_properties ()

GParamSpec **
json_serializable_list_properties (JsonSerializable *serializable,
                                   guint *n_pspecs);

Calls the JsonSerializableIface.list_properties() implementation on the serializable instance.

Parameters

serializable

a JsonSerializable

 

n_pspecs

return location for the length of the array of GParamSpec returned by the function.

[out]

Returns

an array of GParamSpec. Use g_free() to free the array when done.

[array length=n_pspecs][transfer container]

Since: 0.14


json_serializable_set_property ()

void
json_serializable_set_property (JsonSerializable *serializable,
                                GParamSpec *pspec,
                                const GValue *value);

Calls the JsonSerializableIface.set_property() implementation on the serializable instance.

Parameters

serializable

a JsonSerializable

 

pspec

a GParamSpec

 

value

the property value to set

 

Since: 0.14


json_serializable_default_serialize_property ()

JsonNode *
json_serializable_default_serialize_property
                               (JsonSerializable *serializable,
                                const gchar *property_name,
                                const GValue *value,
                                GParamSpec *pspec);

Calls the default implementation of the JsonSerializable JsonSerializableIface.serialize_property() virtual function.

This function can be used inside a custom implementation of the JsonSerializableIface.serialize_property() virtual function in lieu of calling the default implementation through g_type_default_interface_peek():

1
2
3
4
5
6
7
JsonSerializable *iface;
JsonNode *node;

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

Parameters

serializable

a JsonSerializable object

 

property_name

the name of the property

 

value

the value of the property

 

pspec

a GParamSpec

 

Returns

a JsonNode containing the serialized property.

[transfer full]

Since: 0.10


json_serializable_default_deserialize_property ()

gboolean
json_serializable_default_deserialize_property
                               (JsonSerializable *serializable,
                                const gchar *property_name,
                                GValue *value,
                                GParamSpec *pspec,
                                JsonNode *property_node);

Calls the default implementation of the JsonSerializable deserialize_property() virtual function

This function can be used inside a custom implementation of the deserialize_property() virtual function in lieu of:

1
2
3
4
5
6
7
8
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

serializable

a JsonSerializable

 

property_name

the name of the property

 

value

a pointer to an uninitialized GValue

 

pspec

a GParamSpec

 

property_node

a JsonNode containing the serialized property

 

Returns

TRUE if the property was successfully deserialized.

Since: 0.10

Types and Values

struct JsonSerializableIface

struct JsonSerializableIface {
  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);

  GParamSpec * (* find_property)       (JsonSerializable *serializable,
                                        const char       *name);
  GParamSpec **(* list_properties)     (JsonSerializable *serializable,
                                        guint            *n_pspecs);
  void         (* set_property)        (JsonSerializable *serializable,
                                        GParamSpec       *pspec,
                                        const GValue     *value);
  void         (* get_property)        (JsonSerializable *serializable,
                                        GParamSpec       *pspec,
                                        GValue           *value);
};

Interface that allows serializing and deserializing GObject instances 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.

Members

serialize_property ()

virtual function for serializing a GObject property into a JsonNode

 

deserialize_property ()

virtual function for deserializing a JsonNode into a GObject property

 

find_property ()

virtual function for finding a property definition using its name

 

list_properties ()

virtual function for listing the installed property definitions

 

set_property ()

virtual function for setting a property

 

get_property ()

virtual function for getting a property

 
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.