apupier commented on code in PR #21086:
URL: https://github.com/apache/camel/pull/21086#discussion_r2732484936


##########
core/camel-console/src/main/java/org/apache/camel/impl/console/BeanDevConsole.java:
##########
@@ -176,6 +136,64 @@ protected JsonObject doCallJson(Map<String, Object> 
options) {
         return root;
     }
 
+    private JsonObject buildBeanJson(String name, Object bean, 
BeanIntrospection bi, boolean properties, boolean nulls) {
+        JsonObject jb = new JsonObject();
+        jb.put("name", name);
+        jb.put("type", bean.getClass().getName());
+
+        if (!properties) {
+            return jb;
+        }
+
+        Map<String, Object> values = new TreeMap<>();
+        try {
+            bi.getProperties(bean, values, null);
+        } catch (Throwable e) {
+            // ignore
+        }
+
+        if (!values.isEmpty()) {
+            JsonArray arr = new JsonArray();
+            values.forEach((pk, pv) -> addPropertyToArray(arr, pk, pv, nulls));
+            jb.put("properties", arr);
+        }
+
+        return jb;
+    }
+
+    private void addPropertyToArray(JsonArray arr, String pk, Object pv, 
boolean nulls) {
+        Object value = resolvePropertyValue(pv);
+        if (value == null && !nulls) {
+            return;
+        }
+
+        JsonObject jp = new JsonObject();
+        jp.put("name", pk);
+        if (pv != null) {
+            jp.put("type", pv.getClass().getName());
+        }
+        jp.put("value", value);
+        arr.add(jp);
+    }
+
+    private Object resolvePropertyValue(Object pv) {
+        if (pv == null) {
+            return null;
+        }
+        Object serialized = Jsoner.trySerialize(pv);
+        if (serialized == null) {
+            return Jsoner.escape(pv.toString());
+        }
+        return pv;
+    }

Review Comment:
   we lost the comments, I'm not a fan of comment but I think here we need them 
as the behavior is not easy to understand



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to