Castor - Unmarshal empty string as null
How to unmarshal an empty string 开发者_运维知识库as null while using Castor?
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>
精彩评论