private static void printArrayProperty(final StringBuffer sb, final String prefix, final Object array) { final int length = Array.getLength(array); for (int i = 0; i < length; i++) { final Object obj = Array.get(array, i); printProperty(sb, String.format("%s[%s]", prefix, i), obj); } }
private static void printArrayProperty(final StringBuffer sb, final String prefix, final Object array) { final int length = Array.getLength(array); for (int i = 0; i < length; i++) { final Object obj = Array.get(array, i); printProperty(sb, String.format("%s[%s]", prefix, i), obj); } }
/** * Returns the String representation of the bean given in the constructor. * <p> * * @param prefix to use for bean properties. * @return bean object String representation. * */ private static String toString(final Class<?> beanClass, final Object obj, final String prefix) { final StringBuffer sb = new StringBuffer(128); try { final List<PropertyDescriptor> propertyDescriptors = BeanIntrospector.getPropertyDescriptorsWithGetters(beanClass); for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) { final String propertyName = propertyDescriptor.getName(); final Method getter = propertyDescriptor.getReadMethod(); final Object value = getter.invoke(obj, NO_PARAMS); printProperty(sb, prefix + "." + propertyName, value); } } catch (final Exception e) { LOG.error("Error while generating toString", e); final Class<?> clazz = obj.getClass(); final String errorMessage = e.getMessage(); sb.append(String.format("\n\nEXCEPTION: Could not complete %s.toString(): %s\n", clazz, errorMessage)); } return sb.toString(); }
/** * Returns the String representation of the bean given in the constructor. * <p> * * @param prefix to use for bean properties. * @return bean object String representation. * */ private static String toString(final Class<?> beanClass, final Object obj, final String prefix) { final StringBuffer sb = new StringBuffer(128); try { final List<PropertyDescriptor> propertyDescriptors = BeanIntrospector.getPropertyDescriptorsWithGetters(beanClass); for (final PropertyDescriptor propertyDescriptor : propertyDescriptors) { final String propertyName = propertyDescriptor.getName(); final Method getter = propertyDescriptor.getReadMethod(); final Object value = getter.invoke(obj, NO_PARAMS); printProperty(sb, prefix + "." + propertyName, value); } } catch (final Exception e) { LOG.error("Error while generating toString", e); final Class<?> clazz = obj.getClass(); final String errorMessage = e.getMessage(); sb.append(String.format("\n\nEXCEPTION: Could not complete %s.toString(): %s\n", clazz, errorMessage)); } return sb.toString(); }