Skip to content

Commit

Permalink
Flattening values in JMX attributes of Map type
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Nov 16, 2017
1 parent 9b149f2 commit 2c023b6
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2c023b6

Please sign in to comment.