How to print bean properties
Jodd is an open-source java library with lot of reusable components and feature rich utilities.
This requires the library jodd-3.3.2.jar to be in classpath.
The following example shows how to print bean properties as per their scoope
using BeanTool.attributesToString() API.
package com.bethecoder.tutorials.jodd.common;
public class AttributeBean {
private String privateProp;
protected Long protectedProp;
public Double publicProp;
public AttributeBean ( String privateProp, Long protectedProp,
Double publicProp ) {
super () ;
this .privateProp = privateProp;
this .protectedProp = protectedProp;
this .publicProp = publicProp;
}
}
package com.bethecoder.tutorials.jodd.beans;
import jodd.bean.BeanTool;
import com.bethecoder.tutorials.jodd.common.AttributeBean;
public class AttributesToStringTest {
/**
* @param args
*/
public static void main ( String [] args ) {
AttributeBean bean = new AttributeBean ( "ABCD" , 1234L , 56.789 ) ;
String attribString = BeanTool.attributesToString ( bean ) ;
System.out.println ( attribString ) ;
}
}
It gives the following output,
#protectedProp:1234
+publicProp:56.789
-privateProp:ABCD