Mercurial Hosting > luan
changeset 1802:ca98dee04e08
add Parsers.json_null
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 21 Apr 2024 21:25:15 -0600 |
parents | 32e77b071e09 |
children | d1dd61e6dd84 |
files | src/luan/Luan.java src/luan/modules/BasicLuan.java src/luan/modules/Parsers.luan |
diffstat | 3 files changed, 9 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
diff -r 32e77b071e09 -r ca98dee04e08 src/luan/Luan.java --- a/src/luan/Luan.java Tue Mar 12 09:28:39 2024 -0600 +++ b/src/luan/Luan.java Sun Apr 21 21:25:15 2024 -0600 @@ -423,14 +423,16 @@ return load(text,sourceName,persist,null); } - public static Object toJava(Object obj) throws LuanException { + public static Object toJava(Object obj,Object nullValue) throws LuanException { + if( obj == nullValue ) + return null; if( !(obj instanceof LuanTable) ) return obj; LuanTable tbl = (LuanTable)obj; if( !tbl.isMap() ) { List list = new ArrayList(); for( Object el : tbl.asList() ) { - list.add( toJava(el) ); + list.add( toJava(el,nullValue) ); } return list; } else { @@ -438,7 +440,7 @@ Iterator<Map.Entry> iter = tbl.rawIterator(); while( iter.hasNext() ) { Map.Entry entry = iter.next(); - map.put( toJava(entry.getKey()), toJava(entry.getValue()) ); + map.put( toJava(entry.getKey(),nullValue), toJava(entry.getValue(),nullValue) ); } return map; }
diff -r 32e77b071e09 -r ca98dee04e08 src/luan/modules/BasicLuan.java --- a/src/luan/modules/BasicLuan.java Tue Mar 12 09:28:39 2024 -0600 +++ b/src/luan/modules/BasicLuan.java Sun Apr 21 21:25:15 2024 -0600 @@ -227,6 +227,8 @@ throw new LuanException("options must be table of function"); } + public static final Object json_null = new Object(); + public static String json_string(Object obj,LuanTable options) throws LuanException { JsonToString jts = new JsonToString(); if( options != null ) { @@ -236,7 +238,7 @@ jts.compressed = compressed; Utils.checkEmpty(options); } - return jts.toString(Luan.toJava(obj)); + return jts.toString(Luan.toJava(obj,json_null)); } public static Object get_local_cloned(Luan luan,Object obj,Object key) {
diff -r 32e77b071e09 -r ca98dee04e08 src/luan/modules/Parsers.luan --- a/src/luan/modules/Parsers.luan Tue Mar 12 09:28:39 2024 -0600 +++ b/src/luan/modules/Parsers.luan Sun Apr 21 21:25:15 2024 -0600 @@ -14,6 +14,7 @@ Parsers.bbcode_encode = BBCode.encode Parsers.bbcode_parse = BBCodeLuan.parse Parsers.csv_to_list = Csv.toList +Parsers.json_null = BasicLuan.json_null Parsers.json_string = BasicLuan.json_string Parsers.theme_to_luan = Theme.toLuan Parsers.xml_encode = XmlElement.encode