Print class list attribute in xml

Asked

Viewed 64 times

-1

How can I generate an xml file in java, from a class that receives an Arraylist as attribute. I am not able to access the indexes of this Arraylist at the time of passing to the string that will be saved in xml.

1 answer

0


I don’t know which lib you’re using to serialize objects in XML, but I usually use Xstream.

In case of serializing a list of products of an object Carrinho which has a list of products:

XStream xstream = new XStream();
xstream.alias("Produtos", List.class);
xstream.toXML(carrinho.getProdutos());
  • Anything, send your code and I’ll take a look...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.