Flattening values in JMX attributes of Map type
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.management.Attribute;
@@ -213,7 +214,13 @@ private ObjectName generateObjectName(Object bean) {
public Object getAttribute(String attribute)
throws AttributeNotFoundException, MBeanException, ReflectionException {
try {
- return attributeMap.get(attribute).getter.invoke(bean);
+ Object res = attributeMap.get(attribute).getter.invoke(bean);
+ if (res instanceof Map<?,?>) {
+ return ((Map<?,?>) res).entrySet().stream().collect(Collectors.toMap(
+ Map.Entry::getKey, e -> e.getValue().toString()));
+ } else {
+ return res;
+ }
} catch (IllegalAccessException|InvocationTargetException e) {
e.printStackTrace();
return null;
