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


##########
core/camel-console/src/main/java/org/apache/camel/impl/console/BeanDevConsole.java:
##########
@@ -122,52 +127,12 @@ protected JsonObject doCallJson(Map<String, Object> 
options) {
             Stream<String> keys = beans.keySet().stream().filter(r -> 
accept(r, filter)).sorted(String::compareToIgnoreCase);
             keys.forEach(k -> {
                 Object bean = beans.get(k);
-                if (bean != null) {
-                    boolean include = internal || 
!bean.getClass().getName().startsWith("org.apache.camel.");
-                    if (include) {
-                        Map<String, Object> values = new TreeMap<>();
-                        if (properties) {
-                            try {
-                                bi.getProperties(bean, values, null);
-                            } catch (Throwable e) {
-                                // ignore
-                            }
-                        }
-                        JsonObject jb = new JsonObject();
-                        jb.put("name", k);
-                        jb.put("type", bean.getClass().getName());
-                        jo.put(k, jb);
-
-                        if (!values.isEmpty()) {
-                            JsonArray arr = new JsonArray();
-                            values.forEach((pk, pv) -> {
-                                Object value = pv;
-                                String type = pv != null ? 
pv.getClass().getName() : null;
-                                if (type != null) {
-                                    value = Jsoner.trySerialize(pv);
-                                    if (value == null) {
-                                        // cannot serialize so escape
-                                        value = Jsoner.escape(pv.toString());
-                                    } else {
-                                        // okay so use the value as-s
-                                        value = pv;
-                                    }
-                                }
-                                JsonObject jp = new JsonObject();
-                                jp.put("name", pk);
-                                if (type != null) {
-                                    jp.put("type", type);
-                                }
-                                jp.put("value", value);
-                                boolean accept = value != null || nulls;
-                                if (accept) {
-                                    arr.add(jp);
-                                }
-                            });
-                            jb.put("properties", arr);
-                        }
-                    }
+                if (!shouldIncludeBean(bean, internal)) {
+                    return;
                 }
+
+                JsonObject jb = buildBeanJson(k, bean, bi, properties, nulls);
+                jo.put(k, jb);

Review Comment:
   to avoid negation, keep happy path at the top, avoid ambigous `return` and 
reduce amount of code:
   
   ```
                   if (shouldIncludeBean(bean, internal)) {
                       JsonObject jb = buildBeanJson(k, bean, bi, properties, 
nulls);
                       jo.put(k, jb);
                   }
   ```



-- 
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