You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2026/06/17 13:31:05 UTC
(velocity-tools) branch master updated: VELTOOLS-184 (#13) - make json() a synonym for java()
This is an automated email from the ASF dual-hosted git repository.
arkanovicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/velocity-tools.git
The following commit(s) were added to refs/heads/master by this push:
new 62bdf6ee VELTOOLS-184 (#13) - make json() a synonym for java()
62bdf6ee is described below
commit 62bdf6eeb22be106bcd86eca17310a01e6715fb9
Author: David Walton <dw...@digger.net>
AuthorDate: Wed Jun 17 13:31:00 2026 +0000
VELTOOLS-184 (#13) - make json() a synonym for java()
---
.../org/apache/velocity/tools/generic/EscapeTool.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java b/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
index c4b5aa03..43fd6d41 100644
--- a/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
+++ b/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/EscapeTool.java
@@ -44,6 +44,9 @@ import org.apache.velocity.tools.config.ValidScope;
* $javascript -> He didn't say, "Stop!"
* $esc.javascript($javascript) -> He didn\'t say, \"Stop!\"
*
+ * $json -> He didn't say, "Stop!"
+ * $esc.json($json) -> He didn't say, \"Stop!\"
+ *
* $html -> "bread" & "butter"
* $esc.html($html) -> &quot;bread&quot; &amp; &quot;butter&quot;
*
@@ -364,6 +367,18 @@ public class EscapeTool extends SafeConfig implements Serializable
return StringEscapeUtils.escapeEcmaScript(String.valueOf(string));
}
+ /**
+ * <p>Escapes the characters in a <code>String</code> using JSON String rules.</p>
+ * <p>Delegates the process to {@link #java(String)}.</p>
+ *
+ * @param string the string to escape values, may be null
+ * @return String with escaped values, <code>null</code> if null string input
+ */
+ public String json(Object string)
+ {
+ return java(string);
+ }
+
/**
* <p>Escapes the characters in a <code>String</code> using HTML entities.</p>
* <p>Delegates the process to {@link StringEscapeUtils#escapeHtml4(String)}.</p>