How can I generate an xml file in java, from a class that receives an ArrayList as an attribute. I am not able to access the Arraylist indices when I move to the string that will be saved in xml.
How can I generate an xml file in java, from a class that receives an ArrayList as an attribute. I am not able to access the Arraylist indices when I move to the string that will be saved in xml.
I do not know which lib you're using to serialize XML objects, but I usually use Xstream .
In case of serializing a list of products of a Carrinho
object that has a list of products:
XStream xstream = new XStream();
xstream.alias("Produtos", List.class);
xstream.toXML(carrinho.getProdutos());