First attempt to implement JsonSerializable

This commit is contained in:
Gergely Polonkai 2016-10-18 17:56:25 +02:00
parent 42d9ab7716
commit dd6fd39ae3

View File

@ -19,7 +19,9 @@
/** /**
* Base class for Matrix events. * Base class for Matrix events.
*/ */
public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable { public abstract class Matrix.Event.Base : GLib.Object,
GLib.Initable,
Json.Serializable {
private Error? _construct_error = null; private Error? _construct_error = null;
private bool _inited = false; private bool _inited = false;
private Json.Node? _json; private Json.Node? _json;
@ -77,6 +79,8 @@ public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable {
} }
} }
// Implementation of GLib.Initable
public bool public bool
init(GLib.Cancellable? cancellable = null) init(GLib.Cancellable? cancellable = null)
throws Error, Matrix.Error throws Error, Matrix.Error
@ -95,6 +99,39 @@ public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable {
return true; return true;
} }
// Implementation of Json.Serializable
public unowned ParamSpec
find_property(string name)
{
return get_class().find_property(name);
}
public Json.Node
serialize_property(string property_name,
Value value,
ParamSpec pspec)
{
return default_serialize_property(property_name, value, pspec);
}
public bool
deserialize_property(string property_name,
out Value value,
ParamSpec pspec,
Json.Node property_node)
{
value = Value(pspec.value_type);
return default_deserialize_property(property_name,
value,
pspec,
property_node);
}
// Own methods
private void private void
initialize_from_json(Json.Node json_data) initialize_from_json(Json.Node json_data)
throws Matrix.Error throws Matrix.Error