1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ConvertTypes.java Sun Mar 31 05:34:15 2013 +0200
1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/ConvertTypes.java Wed Apr 03 10:20:17 2013 +0200
1.3 @@ -50,6 +50,22 @@
1.4 throw new IllegalStateException("Value " + ret + " is not of type " + modelClass);
1.5 }
1.6
1.7 + public static String toJSON(Object value) {
1.8 + if (value == null) {
1.9 + return "null";
1.10 + }
1.11 + if (value instanceof String) {
1.12 + return '"' +
1.13 + ((String)value).
1.14 + replace("\"", "\\\"").
1.15 + replace("\n", "\\n").
1.16 + replace("\r", "\\r").
1.17 + replace("\t", "\\t")
1.18 + + '"';
1.19 + }
1.20 + return value.toString();
1.21 + }
1.22 +
1.23 @JavaScriptBody(args = { "object", "property" },
1.24 body = "if (property === null) return object;\n"
1.25 + "var p = object[property]; return p ? p : null;"