Commits

Christophe de Vienne committed 348370d

Fix json null values decoding

Comments (0)

Files changed (2)

tgwebservices/iconv.py

         return _get_json_value(value, itype.type)
     elif not isinstance(itype, type):
         return _get_json_value(value, type(itype))
+    elif value is None:
+        return None
     elif itype == datetime.date:
         return date_converter(value)
     elif itype == datetime.time:

tgwebservices/tests/test_json.py

 
     assert data == rdata[::-1]
 
+def test_null():
+    cherrypy.root = ComplexService("http://foo.bar.baz/")
+    
+    request = """{"rwp": {"value": null}}"""
+    testutil.create_request("/getandsetrwprop", rfile=StringIO.StringIO(request), 
+                            method="POST", 
+                            headers={"Content-Length" : str(len(request)),
+                                     "Content-Type" : 
+                                        "application/json; charset=utf-8",
+                                     "Accept" : 
+                                        "application/json"})
+    output = cherrypy.response.body[0]
+    print output
+    assert output == """{"result": {"value": null}}"""
+