Hi,

is there a simple way to hook into parse/stringify of qx.io.remote.Rpc, so 
that I can handle __jsonclass__ style class hints that my server is providing?

Maybe it would be nice to have the option of adding hooks for that in the Rpc 
class in the future? There's a simple patch attached which calls these hooks 
if defined. Date handling is ignored when hooks are defined.

Cheers,
Cajus
diff --git a/framework/source/class/qx/io/remote/Rpc.js b/framework/source/class/qx/io/remote/Rpc.js
index 828d716..cb9ce0e 100644
--- a/framework/source/class/qx/io/remote/Rpc.js
+++ b/framework/source/class/qx/io/remote/Rpc.js
@@ -399,6 +399,26 @@ qx.Class.define("qx.io.remote.Rpc",
     {
       init : "qx1",
       check : function(val) { return val == "qx1" || val == "2.0"; }
+    },
+
+    /**
+     * Reviver function to call when parsing JSON responses. Null if no
+     * preprocessing is used.
+     */
+    parseHook :
+    {
+      check : "Function",
+      nullable : true
+    },
+
+    /**
+     * Replacer function to call when stringifying JSON data. Null if no
+     * replacer is used.
+     */
+    stringifyHook :
+    {
+      check : "Function",
+      nullable : true
     }
   },
 
@@ -719,7 +739,7 @@ qx.Class.define("qx.io.remote.Rpc",
 
           // No special date handling required, JSON assumed
           } else {
-            response = qx.lang.Json.parse(response);
+            response = qx.lang.Json.parse(response, self.getParseHook());
           }
         }
 
@@ -768,7 +788,7 @@ qx.Class.define("qx.io.remote.Rpc",
       });
 
       // Provide a replacer when convert dates is enabled
-      var replacer = null;
+      var replacer = this.getStringifyHook();
       if (this._isConvertDates()) {
         replacer = function(key, value) {
           // The value passed in is of type string, because the Date's
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to