DEV Community

Query Filter
Query Filter

Posted on

bridge90

private String extractValue(Object value) {
        if (value == null) return "null";

        if (value instanceof BeanReference) {
            return "@" + ((BeanReference) value).getBeanName();
        }

        // NEW: If the list contains an anonymous/inner bean definition
        if (value instanceof BeanDefinition) {
            String className = ((BeanDefinition) value).getBeanClassName();
            if (className != null) {
                // Return just the short class name to keep the box small
                return className.substring(className.lastIndexOf('.') + 1);
            }
            return "InnerBean";
        }

        if (value instanceof TypedStringValue) {
            return ((TypedStringValue) value).getValue();
        }

        if (value instanceof List) {
            List<String> cleaned = new ArrayList<>();
            for (Object item : (List<?>) value) {
                cleaned.add(extractValue(item)); // Recursive call handles inner beans in lists
            }
            // Use <BR/> for vertical stacking inside the HTML table
            return String.join("<BR ALIGN=\"LEFT\"/>", cleaned);
        }

        if (value instanceof Map) {
            StringBuilder mapStr = new StringBuilder();
            for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
                mapStr.append(extractValue(entry.getKey()))
                      .append("=")
                      .append(extractValue(entry.getValue()))
                      .append("<BR ALIGN=\"LEFT\"/>");
            }
            return mapStr.toString();
        }

        return value.toString();
    }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)