[json-glib] Avoid serializing default property values only after consulting the JsonSerializable.



commit 4315308a19e4cf474451cecf8b69aceddda91f49
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sat Jul 9 15:23:36 2011 -0400

    Avoid serializing default property values only after
    consulting the JsonSerializable.
    
    This patch gives the JsonSerializable class a chance to decide
    whether it's appropriate to serialize a property before
    JsonGObject checks for a default value and skips the property.

 json-glib/json-gobject.c      |   10 ++--------
 json-glib/json-serializable.c |    4 ++++
 2 files changed, 6 insertions(+), 8 deletions(-)
---
diff --git a/json-glib/json-gobject.c b/json-glib/json-gobject.c
index 73ecaac..0b91a5e 100644
--- a/json-glib/json-gobject.c
+++ b/json-glib/json-gobject.c
@@ -400,13 +400,6 @@ json_gobject_dump (GObject *gobject)
       else
         g_object_get_property (gobject, pspec->name, &value);
 
-      /* skip if the value is the default for the property */
-      if (g_param_value_defaults (pspec, &value))
-        {
-          g_value_unset (&value);
-          continue;
-        }
-
       /* if there is a serialization vfunc, then it is completely responsible
        * for serializing the property, possibly by calling the implementation
        * of the default JsonSerializable interface through chaining up
@@ -417,7 +410,8 @@ json_gobject_dump (GObject *gobject)
                                             &value,
                                             pspec);
         }
-      else
+      /* skip if the value is the default for the property */
+      else if (!g_param_value_defaults (pspec, &value))
         node = json_serialize_pspec (&value, pspec);
 
       if (node)
diff --git a/json-glib/json-serializable.c b/json-glib/json-serializable.c
index c90a687..e49ccb1 100644
--- a/json-glib/json-serializable.c
+++ b/json-glib/json-serializable.c
@@ -123,6 +123,10 @@ json_serializable_real_serialize (JsonSerializable *serializable,
                                   GParamSpec       *pspec)
 {
   JSON_NOTE (GOBJECT, "Default serialization for property '%s'", pspec->name);
+
+  if (g_param_value_defaults (pspec, (GValue *)value))
+    return NULL;
+
   return json_serialize_pspec (value, pspec);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]