summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2018-05-18 16:59:16 +0200
committerJo-Philipp Wich <jo@mein.io>2018-05-18 16:59:16 +0200
commit09de5a74e13b225c2159bd62bef2563bd2a615c2 (patch)
tree96561f7971c4c4b8ddfb2ae9505c94d12d0ffdb2
parent364c271a84210a841762beeb2dd0715cd7c2e240 (diff)
luci-lib-json: support serializing userdata
Fixes the following error when attempting to serialize userdata objects: .../json.lua:81: attempt to call local 'parser' (a nil value) Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--libs/luci-lib-json/luasrc/json.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/libs/luci-lib-json/luasrc/json.lua b/libs/luci-lib-json/luasrc/json.lua
index f7b57f916..6d4d752b1 100644
--- a/libs/luci-lib-json/luasrc/json.lua
+++ b/libs/luci-lib-json/luasrc/json.lua
@@ -181,13 +181,18 @@ function Encoder.parse_iter(self, obj)
end
end
+function Encoder.parse_udata(self, obj)
+ return self:parse_string(tostring(obj))
+end
+
Encoder.parsers = {
['nil'] = Encoder.parse_nil,
['table'] = Encoder.parse_iter,
['number'] = Encoder.parse_number,
['string'] = Encoder.parse_string,
['boolean'] = Encoder.parse_bool,
- ['function'] = Encoder.parse_iter
+ ['function'] = Encoder.parse_iter,
+ ['userdata'] = Encoder.parse_udata,
}