0

我有以下豆:

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 中删除空列表?

4

0 回答 0