如何在使用Castor时将空字符串解组为null?
答案 0 :(得分:0)
public class EmptyStringHandler extends GeneralizedFieldHandler {
public Object convertUponGet(Object arg0) {
//we don't know if it was really null or not, so just return it
return arg0;
}
public Object convertUponSet(Object arg0) {
if("".equals(arg0)) {
return null;
}
return arg0;
}
public Class getFieldType() {
return String.class;
}
}
<field name="amid" type="integer" required="true" handler="cat.dds.fpsdma.fieldhandlers.EmptyIntegerHandler">
<bind-xml name="AMID" node="element" />
</field>