This code is to get all of the bean's property information and encapsulate it into a PropertyDescriptor description class.
Deep getpropertydescriptors () Analysis:
if (Beanclass = = null) {
throw new IllegalArgumentException ("No Bean class specified")
;
Look up any cached descriptors for this bean class
propertydescriptor[] descriptors = null;
descriptors =
(propertydescriptor[]) descriptorscache.get (beanclass);
if (descriptors!= null) {return
(descriptors);
}
Introspect The bean and cache the generated descriptors
BeanInfo BeanInfo = null;
try {
beanInfo = Introspector.getbeaninfo (Beanclass);
} catch (Introspectionexception e) {return
(new Propertydescriptor[0]);
}
descriptors = Beaninfo.getpropertydescriptors ();
if (descriptors = = null) {
descriptors = new propertydescriptor[0];
}
Introspector.getbeaninfo (beanclass);
The red area above is the key part, and he gets the Bean's property method through the Java introspection mechanism and returns the BeanInfo class.
To get the rule of a property:
1. The class contains a public get method such as: Getcurruser ()
2, the class contains a public-owned set method, such as: publicly void SetName (String c)
Through the above analysis, the HISTOGRAMVO class has the Setusernum () method does not have the corresponding Getusernum () method to cause the "" JSON. Jsonobject-property ' Usernum ' has no Read method. Skipped "Warning error.
Adding the Getusernum () method solves the problem.
Summarize:
The problem is not complicated, but it is understood by the Java introspection mechanism.
Related documents:
Http://java.sun.com/products/javabeans/docs/index.html
Http://blog.csdn.net/hahalzb/archive/2010/10/28/5972421.aspx