0

I have the following 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;
    }


}

I use apache Betwixt to output XML from my bean.

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);

The listND attribute of my bean is null, but i still get:

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

How can I remove empty lists from the output XML ?

Majid Laissi
  • 19,188
  • 19
  • 68
  • 105
  • Not sure about betwixt, but your use case is the default behaviour in any JAXB (JSR-222) implementation: http://blog.bdoughan.com/2010/09/jaxb-collection-properties.html – bdoughan Nov 01 '12 at 15:10
  • this might be the default behaviour, but i'm asking if there's a configuration that can remove the List from the output. – Majid Laissi Nov 01 '12 at 15:20

0 Answers0