/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* * core-json-api-simple-object.vala * Copyright (C) 2015 Luc Chante * */ public class Core.JsonApi.SimpleObject : Object, Json.Serializable { public bool serialize_default_value = false; public SimpleObject () { Object (); } // {{{ Serialization /** * Calls the JsonSerializableIface.list_propertiess implementation on the this instance. */ public new ParamSpec[] list_properties () { debug ("list_properties()"); return get_class ().list_properties (); } /** * Asks a Serializable implementation to serialize a Object property into a Node object. */ public Json.Node serialize_property (string property_name, Value value, ParamSpec pspec) { Json.Node node = default_serialize_property (property_name, value, pspec); if (node != null) debug ("serialize_property(%s %s) => %s", Core.get_fundamental (pspec.value_type).name (), property_name, node.dup_string ()); else { Value strval = Value (typeof(string)); value.transform (ref strval); debug ("serialize_property(%s %s, %s)", Core.get_fundamental (pspec.value_type).name (), property_name, strval.get_string ()); } return node; } /** * Calls the get_property implementation on the this instance. */ #if VALA_0_28 public new Value get_property (ParamSpec pspec) { #else public new void get_property (ParamSpec pspec, Value value) { #endif Value result = Value (pspec.value_type); base.get_property (pspec.name, ref result); Value strval = Value (typeof (string)); result.transform (ref strval); debug ("get_property(%s) => %s", pspec.name, strval.get_string ()); #if VALA_0_28 return result; #else value = result; #endif } // }}} // {{{ Deserialization /** * Calls the find_property implementation on the this instance. */ public unowned ParamSpec find_property (string name) { debug ("find_property(%s)", name); return get_class ().find_property (name); } /** * Asks a Serializable implementation to deserialize the property contained inside property_node into value. */ public bool deserialize_property (string property_name, out Value value, ParamSpec pspec, Json.Node property_node) { debug ("deserialize_property(%s)", property_name); value = Value (pspec.value_type); return default_deserialize_property (property_name, value, pspec, property_node); } /** * Calls the set_property implementation on the this instance. */ public new void set_property (ParamSpec pspec, Value value) { debug ("set_property(%s)", pspec.name); base.set_property (pspec.name, value); } // }}} }