0

I have the following code:

public static void main(String[] args) throws IOException, JAXBException
{
    Shop shop=new Shop();
    shop.names.add("S1");
    shop.names.add("S2");
    shop.count=12;
    shop.profit=123.4;
    shop.secretData.add("String1");
    shop.secretData.add("String2");
    shop.secretData.add("String3");
    shop.secretData.add("String4");
    shop.secretData.add("String5");
    StringWriter writer = new StringWriter();
    convertToXml(writer, shop);
    System.out.println(writer.toString());
    //toXmlWithComment(shop, "second", "it's a comment");
}





public static void convertToXml(StringWriter writer, Object obj) throws IOException, JAXBException
{
    JAXBContext context = JAXBContext.newInstance(obj.getClass());
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.marshal(obj, writer);
}

Maybe I need to use one of the method of Marshaller but I don't now it. How to insert comments?

Taras Melnyk
  • 3,057
  • 3
  • 38
  • 34

0 Answers0