Print list attribute of a class in xml [closed]

-1

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.

    
asked by anonymous 09.08.2018 / 18:38

1 answer

0

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());
    
09.08.2018 / 18:54