tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Jodd > Beans > How to print bean properties

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.

File Name  :  
com/bethecoder/tutorials/jodd/common/AttributeBean.java 
   
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;
  }
}
   

File Name  :  
com/bethecoder/tutorials/jodd/beans/AttributesToStringTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
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"1234L56.789);
    String attribString = BeanTool.attributesToString(bean);
    System.out.println(attribString);
  }

}
   

It gives the following output,
#protectedProp:1234
+publicProp:56.789
-privateProp:ABCD


                    Print

   



Books Recommendation

 
 
bl  br