The adapter class:
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class BooleanAdapter extends XmlAdapter<Integer, Boolean>
{
@Override
public Boolean unmarshal( Integer s )
{
return s == null ? null : s == 1;
}
@Override
public Integer marshal( Boolean c )
{
return c == null ? null : c ? 1 : 0;
}
}
Usage:
@XmlElement( name = "enabled" )
@XmlJavaTypeAdapter( BooleanAdapter.class )
public Boolean getEnabled()
{
return enabled;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…