BeanWriter禁用输出空列表

时间:2012-11-01 14:43:07

标签: java xml javabeans betwixt

我有以下bean:

public class ContractBean {

    private List<String> listNd;

    private String nd;

    public List<String> getListNd() {
        return listNd;
    }

    public void setListNd(final List<String> listNd) {
        this.listNd = listNd;
    }

    public String getNd() {
        return nd;
    }

    public void setNd(final String nd) {
        this.nd= nd;
    }


}

我使用apache Betwixt从我的bean输出XML。

final BeanWriter beanWriter = new BeanWriter(outputWriter);
beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
beanWriter.getBindingConfiguration().setMapIDs(false);
beanWriter.enablePrettyPrint();
beanWriter.setWriteEmptyElements(false);
beanWriter.getBindingConfiguration().setObjectStringConverter(new CustomObjectStringConverter());
beanWriter.write(obj);

我的bean的listND属性是null,但我仍然得到:

  <contract>
    <listNd/>
    <nd>22222</nd>
  </contract>

如何从输出XML中删除空列表?

0 个答案:

没有答案