开发者

Castor - Unmarshal empty string as null

开发者 https://www.devze.com 2023-03-02 22:13 出处:网络
How to unmarshal an empty string 开发者_运维知识库as null while using Castor?public class EmptyStringHandler extends GeneralizedFieldHandler {

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消