传统的对象POJO
其实就是普通的对象
public class Document {
private String name;
private int time;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
}
Java Beans API(了解即可)
https://en.wikipedia.org/wiki/JavaBeans
public static void main(String[] args) throws IntrospectionException {
// 内省 可以获取Bean的一些基本信息
BeanInfo beanInfo = Introspector.getBeanInfo(Document.class, Object.class);
Arrays.stream(beanInfo.getPropertyDescriptors()).forEach(
propertyDescriptor -> {
String name = propertyDescriptor.getName();
if ("name".equals(name)) {
propertyDescriptor.setPropertyEditorClass(String2Integer.class);
}
}
);
}
static class String2Integer extends PropertyEditorSupport {
@Override
public void setAsText(String text) throws IllegalArgumentException {
Integer val = Integer.valueOf(text);
setValue(val);
}
}