private String extractValue(Object value) {
if (value == null) return "null";
// 1. Unmask Spring's TypedStringValue immediately
if (value instanceof TypedStringValue) {
String raw = ((TypedStringValue) value).getValue();
return xmlEscape(raw != null ? raw.trim() : "null");
}
// 2. Handle Bean References (@name)
if (value instanceof BeanReference) {
return "@" + ((BeanReference) value).getBeanName();
}
// 3. Handle Inner Bean Definitions (Short Class Name only)
if (value instanceof BeanDefinition) {
String className = ((BeanDefinition) value).getBeanClassName();
if (className != null) {
return "<i>" + className.substring(className.lastIndexOf('.') + 1).trim() + "</i>";
}
return "<i>InnerBean</i>";
}
// 4. Handle Collections (Lists/Sets) - Recursive clean
if (value instanceof Iterable) {
List<String> cleaned = new ArrayList<>();
int count = 0;
for (Object item : (Iterable<?>) value) {
if (count++ >= 15) {
cleaned.add("...");
break;
}
cleaned.add(extractValue(item)); // Recursion handles the TypedStrings inside the list
}
return String.join("<BR ALIGN=\"LEFT\"/>", cleaned);
}
// 5. Handle Maps
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();
}
// Default fallback with aggressive trimming
String result = value.toString().trim();
if (result.length() > 60) {
result = result.substring(0, 57).trim() + "...";
}
return xmlEscape(result);
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)