A note of what happened when using Apache Commons BeanUtils
Bean.java
public class Bean {
private Timestamp timestamp;
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
}
Main.java
public class Main {
public static void main(String[] args) throws Exception {
Bean bean = new Bean();
// 1.9.Prior to 3, Object.getClass()Is interpreted as an accessor"class"Is included in the property list.
BeanUtils.describe(bean);
// => 1.9.Before 3:{class=class test.Bean, timestamp=null}
// 1.9.4:{timestamp=null}
// ※ PropertyUtils.describe(bean)Will give the same result.
// 1.9.Before 3, the behavior when setting an inaccessible property with setProperty and copyProperty is different.
BeanUtils.setProperty(bean, "class", Bean.class);
// =>Nothing is done.
BeanUtils.copyProperty(bean, "class", Bean.class);
// => 1.9.Before 3: java.lang.reflect.InvocationTargetException:Cannot set class occurs.
// 1.9.4: Nothing is executed.(BEANUTILS-Has the behavior changed due to the influence of 520? )
//The behavior when trying to set null for some types of properties is different between setProperty and copyProperty.
BeanUtils.setProperty(bean, "timestamp", null);
// => org.apache.commons.beanutils.ConversionException: No value specified for 'java.sql.Timestamp'Occurs.
BeanUtils.copyProperty(bean, "timestamp", null);
// => 1.8.Before 3: A ConversionException occurred like copyProperty.
// 1.9.After 0: Nothing is executed.(BEANUTILS-Fixed in 454)
}
}