protected void displayResults(Object result, int level) { if (null == result) return; String prefix = StringUtils.repeat(" ", level * 2) + " * "; if (Collection.class.isAssignableFrom(result.getClass())) { @SuppressWarnings("unchecked") Collection<Object> coll = Collection.class.cast(result); for (Object o : coll) displayResults(o, 1 + level); return; } else if ("java.lang".equals(result.getClass().getPackage().getName())) { getLog() .info( prefix + CredentialsUtil.redact("" + result) + " [class: " + result.getClass().getSimpleName() + "]"); return; } BeanMap beanMap = new BeanMap(result); for (Iterator<?> itProperty = beanMap.keyIterator(); itProperty.hasNext(); ) { String propertyName = "" + itProperty.next(); Object propertyValue = beanMap.get(propertyName); if ("class".equals(propertyName)) continue; if (null == propertyValue) continue; Class<?> propertyClass = null; try { propertyClass = beanMap.getType(propertyName); } catch (Exception e) { getLog().warn("Failure on property " + propertyName, e); } if (null == propertyClass) { getLog().info(prefix + propertyName + ": " + CredentialsUtil.redact("" + propertyValue)); } else { getLog() .info( prefix + propertyName + ": " + CredentialsUtil.redact("" + propertyValue) + " [class: " + propertyClass.getSimpleName() + "]"); } } }
public Object getBeanValue(T t) { BeanMap bm = new BeanMap(t); for (Object propertyName : bm.keySet()) { System.out.println( "Property: " + propertyName + " value : " + bm.get(propertyName) + " property type = " + bm.getType(propertyName.toString())); Class clazz = bm.getType(propertyName.toString()); System.out.println(clazz.getName() + " " + clazz.getSimpleName()); writeCell(null, bm.get(propertyName), clazz.getSimpleName(), ""); } System.out.println(bm); return null; }