Bean properties printer - a useful debugging tool
There are many instances when I wanted to just log the properties of a given object (most of the time its a bean). This will be useful in two ways: 1) learn about the concrete type of the object 2) serves as a good learning aid to understand what are all the properties that can be get/set in that object. Of course, if you have the documentation and the source code for the class in question, that would be the ultimate aid. Nevertheless, the following piece of code would be useful to print the properties of the given object/bean, using the getter methods that are available in the object. public static void printProperties(String msg, Object o) { String className = o.getClass().getName(); if(msg != null && msg.length() > 0) logger.info("{} (type {})", msg, className); Method[] methods ...