gobject_serialize


Description:

[ Version ( since = "0.10" ) ]
public Node gobject_serialize (Object gobject)

Creates a Node representing the passed Object instance.

Each member of the returned JSON object will map to a property of the Object

Example: GObject serialization:

public enum MyEnum {
FOO, BAR, FOOBAR
}

public class MyObject : Object {
public string str { get; set; }
public MyEnum en { get; set; }
public int num { get; set; }

public MyObject (string str, MyEnum en, int num) {
this.str = str;
this.num = num;
this.en = en;
}
}

public static int main (string[] args) {
MyObject obj = new MyObject ("my string", MyEnum.FOOBAR, 10);
Json.Node root = Json.gobject_serialize (obj);

// To string: (see gobject_to_data)
Json.Generator generator = new Json.Generator ();
generator.set_root (root);
string data = generator.to_data (null);

// Output:
// ``{"str":"my string","en":2,"num":10}``
print (data);
print ("\n");

return 0;
}

valac --pkg json-glib-1.0 serialization.vala

Parameters:

gobject

a Object

Returns:

the newly created Node of type json_node_object . Use json_node_unref to free the resources allocated by this function


Namespace: Json
Package: json-glib-1.0