Java – printing the contents of a bean
Monday, April 20th, 2009I just discovered this trick, and I’m recording it here so other people don’t have to search as much as I did to find it. To dump the contents of a bean b use this code:
org.apache.commons.beanutils.BeanUtils.describe(b).toString()
This uses reflection to dump the bean field names and values – very useful in debugging. describe returns a HashMap of fields and values – also useful if you want to check that specific fields have been set properly.
[ad#co-1]