[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #39420] object2json doesn't support logical ty
From: |
Keith |
Subject: |
[Octave-bug-tracker] [bug #39420] object2json doesn't support logical types |
Date: |
Mon, 22 Jul 2013 04:17:54 +0000 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36 |
Follow-up Comment #4, bug #39420 (project octave):
OK I've added a couple of tests and checked them for validity with
jsonlint.com. I would have run more test cases but it's pretty simple so I'm
not sure what else would need to be tested.
<pre>
diff --git a/object2json.m b/object2json.m
index f0bdb87..c44c2c7 100644
--- a/object2json.m
+++ b/object2json.m
@@ -98,6 +98,13 @@ function json = object2json (object)
object = replace_non_JSON_escapes (object);
json = [ '"', object, '"' ];
+ case 'logical'
+ if object
+ json = 'true';
+ else
+ json = 'false';
+ endif
+
otherwise
% We don't know what is it so we'll put the class name
json = [ '"', class(object), '"' ];
@@ -187,3 +194,15 @@ function object = replace_non_JSON_escapes (object)
object = regexprep (object,
'(?<!\)\(?=(\\)*(?!(["\/bfnrt]|([u][0-9A-Fa-f]{4}))+?))', "\\");
endfunction
+
+%!test
+%! assert(object2json([logical(1), logical(0)]), '[true,false]');
+
+%!test
+%! car.name = 'Mzd R8';
+%! car.speedsamples = [98, 33, 50; 56, 120, 102; 77, 82, 93];
+%! car.toofast = car.speedsamples >= 90;
+%! car.leased = logical(1);
+%! car.european = logical(0);
+%! assert(object2json(car), '{"name":"Mzd
R8","speedsamples":[[98,33,50],[56,120,102],[77,82,93]],"toofast":[[true,false,false],[false,true,true],[false,false,true]],"le
+
</pre>
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?39420>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/