From 0d61c4bdb1e1b1cc1aa45346fa146ca3924c5ed6 Mon Sep 17 00:00:00 2001 From: Qianqian Fang Date: Sun, 28 Apr 2019 19:25:55 -0400 Subject: [PATCH] complete data compression support, close #52 --- savejson.m | 13 +++++++++---- struct2jdata.m | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/savejson.m b/savejson.m index 88d7f90..557a5d0 100644 --- a/savejson.m +++ b/savejson.m @@ -116,7 +116,11 @@ end try error(javachk('jvm')); - matlab.net.base64decode('test'); + try + base64decode('test'); + catch + matlab.net.base64decode('test'); + end catch error('java-based compression is not supported'); end @@ -391,6 +395,10 @@ dozip=jsonopt('Compression','',varargin{:}); zipsize=jsonopt('CompressArraySize',100,varargin{:}); +if(islogical(item)) + item=uint8(item); +end + if(length(size(item))>2 || issparse(item) || ~isreal(item) || ... (isempty(item) && any(size(item))) ||jsonopt('ArrayToStruct',0,varargin{:}) || (~isempty(dozip) && numel(item)>zipsize)) if(isempty(name)) @@ -471,9 +479,6 @@ if(~isempty(dozip) && numel(item)>zipsize) if(isreal(item)) fulldata=item(:)'; - if(islogical(fulldata)) - fulldata=int32(fulldata); - end else txt=sprintf(dataformat,txt,padding0,'"_ArrayIsComplex_": ','1', sep); fulldata=[real(item(:)) imag(item(:))]; diff --git a/struct2jdata.m b/struct2jdata.m index 7b4873c..17b54a2 100644 --- a/struct2jdata.m +++ b/struct2jdata.m @@ -42,7 +42,7 @@ fn=fieldnames(data); newdata=data; len=length(data); -needbase64=jsonopt('Base64',0,varargin{:}); +needbase64=jsonopt('Base64',1,varargin{:}); if(jsonopt('Recursive',0,varargin{:})==1) for i=1:length(fn) % depth-first for j=1:len