This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 441c9eb5d6a camel-core: Fix variable dev console serializing json data
441c9eb5d6a is described below

commit 441c9eb5d6ae449fb7326bd8acf5929904d4f370
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Fri May 16 11:25:05 2025 +0200

    camel-core: Fix variable dev console serializing json data
---
 .../camel/impl/console/VariablesDevConsole.java    | 23 ++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/VariablesDevConsole.java
 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/VariablesDevConsole.java
index bb36068f931..eec27287dc6 100644
--- 
a/core/camel-console/src/main/java/org/apache/camel/impl/console/VariablesDevConsole.java
+++ 
b/core/camel-console/src/main/java/org/apache/camel/impl/console/VariablesDevConsole.java
@@ -25,6 +25,7 @@ import org.apache.camel.spi.BrowsableVariableRepository;
 import org.apache.camel.spi.annotations.DevConsole;
 import org.apache.camel.support.console.AbstractDevConsole;
 import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
 
 @DevConsole(name = "variables", description = "Displays variables")
 public class VariablesDevConsole extends AbstractDevConsole {
@@ -73,13 +74,27 @@ public class VariablesDevConsole extends AbstractDevConsole 
{
         for (Map.Entry<String, Object> entry : repo.getVariables().entrySet()) 
{
             String k = entry.getKey();
             Object v = entry.getValue();
-            String t = v != null ? v.getClass().getName() : null;
+            String type = v != null ? v.getClass().getName() : null;
+            Object value = null;
+            if (type != null) {
+                value = Jsoner.trySerialize(v);
+                if (value == null) {
+                    // cannot serialize so escape
+                    value = Jsoner.escape(v.toString());
+                } else {
+                    // okay so use the value as-s
+                    value = v;
+                }
+            }
+
             JsonObject e = new JsonObject();
             e.put("key", k);
-            if (t != null) {
-                e.put("type", t);
+            if (type != null) {
+                e.put("type", type);
+            }
+            if (value != null) {
+                e.put("value", value);
             }
-            e.put("value", v);
             arr.add(e);
         }
         return arr;

Reply via email to