How do I list property names of a Bean?

package org.kodejava.example.bean;

import java.io.Serializable;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.beans.IntrospectionException;

public class Fruit implements Serializable {
    private Long id;
    private String name;
    private String latinName;
    private double price;

    public Fruit() {
    }

    public static void main(String[] args) {
        try {
            BeanInfo bi = Introspector.getBeanInfo(Fruit.class);
            PropertyDescriptor[] pds = bi.getPropertyDescriptors();

            for (PropertyDescriptor pd : pds) {
                String propertyName = pd.getName();

                System.out.println("propertyName = " + propertyName);
            }
        } catch (IntrospectionException e) {
            e.printStackTrace();
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLatinName() {
        return latinName;
    }

    public void setLatinName(String latinName) {
        this.latinName = latinName;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

How do I prevent bean’s property being serialized to XML?

package org.kodejava.example.bean;

import java.beans.*;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;

public class BeanToXmlTransient {
    private Long id;
    private String itemName;
    private String itemColour;
    private Integer itemQuantities;

    static {
        try {
            // In this block will change the attribute type of the 
            // itemQuantities to transient so it will be not serialized 
            // to xml when we use XMLEncode to convert the bean to xml 
            // persistence.
            BeanInfo bi = Introspector.getBeanInfo(BeanToXmlTransient.class);
            PropertyDescriptor[] pds = bi.getPropertyDescriptors();
            for (int i = 0; i < pds.length; i++) {
                PropertyDescriptor propertyDescriptor = pds[i];
                if (propertyDescriptor.getName().equals("itemQuantities")) {
                    propertyDescriptor.setValue("transient", Boolean.TRUE);
                }
            }
        } catch (IntrospectionException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        BeanToXmlTransient bean = new BeanToXmlTransient();
        bean.setId(new Long(1));
        bean.setItemName("T-Shirt");
        bean.setItemColour("Dark Red");
        bean.setItemQuantities(new Integer(100));

        try {
            XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
                    new FileOutputStream("BeanTransient.xml")));

            // Write an XML representation of the specified object to the 
            // output.
            encoder.writeObject(bean);
            encoder.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getItemColour() {
        return itemColour;
    }

    public void setItemColour(String itemColour) {
        this.itemColour = itemColour;
    }

    public Integer getItemQuantities() {
        return itemQuantities;
    }

    public void setItemQuantities(Integer itemQuantities) {
        this.itemQuantities = itemQuantities;
    }
}

Here will see the the itemQuantities property is not serialized to XML.

<?xml version="1.0" encoding="UTF-8"?> 
<java version="1.6.0_02" class="java.beans.XMLDecoder"> 
 <object class="org.kodejava.example.bean.BeanToXmlTransient"> 
  <void property="id"> 
   <long>1</long> 
  </void> 
  <void property="itemColour"> 
   <string>Dark Red</string> 
  </void> 
  <void property="itemName"> 
   <string>T-Shirt</string> 
  </void> 
 </object> 
</java>