2
How can we remove the tag <list>
automatically generated on XStream
during the serialization process? I have three classes for this scenario: one for test and two to feed data that will be generated in xml.
Test class:
public static void main(String[] args) {
ArrayList<Object> balancos = new ArrayList<Object>();
XStreamBalancoTester tester = new XStreamBalancoTester();
//Serialização
XStream xstream = new XStream(new DomDriver()); //Stax imprime em linha unica com cabeçalho
xstream.autodetectAnnotations(true);
xstream.alias("balanco", Balanco.class);
xstream.alias("operacao", Operacao.class);
xstream.setMode(XStream.NO_REFERENCES);
balancos = tester.getBalancos(5);
String xml = xstream.toXML(balancos);
System.out.println(xml);
XML Generated:
<list>
<balanco>
<id >5< /id>
<compras>
<operacao>
<papel>ub22< /papel>
<valor>30.62< /valor>
<quantidade>150.0< /quantidade>
<data>2020-01-27 19:50:12.937 UTC< /data>
</operacao>
</compras>
</balanco>
</list>
I’ve tried with xstream.omitField(Name.class, “tag”)
and xstream.addImplicitCollection(Name.class, “tag”)
but they didn’t work out.