Easy bean to string conversion using commons-lang

String bnStr=org.apache.commons.lang.builder.ReflectionToStringBuilder.toString(myBean, ToStringStyle.MULTI_LINE_STYLE );
This will print all the properties of the bean by invoking their toString method. This method won’t go down the bean hierarcy to print each nested property. If you want that feature, you write a ParentBean class and override its toString method and make all other beans extend this one. That way, you should be able to see everything in the bean tree.

Credit goes to this:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: