This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push:
new be5ecb790b4 camel-core: Fix variable dev console serializing json data
be5ecb790b4 is described below
commit be5ecb790b4a71ab7722e15c74a8e4cf6283431b
Author: Claus Ibsen <[email protected]>
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;