Created
March 30, 2020 01:15
-
-
Save benwaffle/50fc5d47675c0e806e41eb7c094c3326 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hey : Object, Json.Serializable { | |
public bool? required; | |
private ParamSpec req = new ParamSpecVariant ("required", "required", "required", new VariantType ("mb"), null, ParamFlags.READWRITE); | |
public override void set_property (ParamSpec pspec, Value value) { | |
if (pspec.get_name () == "required") { | |
Variant v = (Variant) value; | |
if (v.get_maybe () != null) | |
required = v.get_maybe ().get_boolean (); | |
else | |
required = null; | |
} else { | |
base.set_property (pspec.get_name (), value); | |
} | |
} | |
public override unowned ParamSpec? find_property (string name) { | |
if (name == "required") { | |
return req; | |
} | |
return this.get_class ().find_property (name); | |
} | |
public override bool deserialize_property (string prop_name, out Value val, ParamSpec pspec, Json.Node property_node) { | |
if (prop_name == "required") { | |
if (property_node.is_null ()) | |
val = new Variant.maybe (VariantType.BOOLEAN, null); | |
else | |
val = new Variant.maybe (VariantType.BOOLEAN, new Variant.boolean (property_node.get_boolean ())); | |
return true; | |
} | |
return default_deserialize_property (prop_name, out val, pspec, property_node); | |
} | |
} | |
void main() { | |
var h = Json.gobject_from_data (typeof (Hey), "{\"required\": true}") as Hey; | |
if (h.required == null) | |
print ("null\n"); | |
else if (h.required) | |
print ("true\n"); | |
else | |
print ("false\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment