camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-7999: apt plugin fixed default value to be json safe
Date Wed, 28 Jan 2015 10:09:08 GMT
Repository: camel
Updated Branches:
  refs/heads/master 223fa08c3 -> 44f82cbf0


CAMEL-7999: apt plugin fixed default value to be json safe


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/44f82cbf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/44f82cbf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/44f82cbf

Branch: refs/heads/master
Commit: 44f82cbf0d1c379a0fc31ebd7d20a1d0acc70fd1
Parents: 223fa08
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Jan 28 11:09:00 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Jan 28 11:09:00 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/tools/apt/JsonSchemaHelper.java    | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/44f82cbf/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java b/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java
index 6f9ee5f..ea78bae 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/JsonSchemaHelper.java
@@ -80,7 +80,8 @@ final class JsonSchemaHelper {
 
         if (!Strings.isNullOrEmpty(defaultValue)) {
             sb.append(", \"defaultValue\": ");
-            sb.append(Strings.doubleQuote(defaultValue));
+            String text = safeDefaultValue(defaultValue);
+            sb.append(Strings.doubleQuote(text));
         }
 
         if (!Strings.isNullOrEmpty(description)) {
@@ -249,4 +250,17 @@ final class JsonSchemaHelper {
         return s.trim();
     }
 
+    /**
+     * The default value may need to be escaped to be safe for json
+     */
+    private static String safeDefaultValue(String value) {
+        if ("\"".equals(value)) {
+            return "\\\"";
+        } else if ("\\".equals(value)) {
+            return "\\\\";
+        } else {
+            return value;
+        }
+    }
+
 }


Mime
View raw message