除了CDATA之外,如何使用编组JAXB在每个标记之前插入注释?

时间:2015-05-20 14:59:10

标签: jaxb

我有以下代码:

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);
}

也许我需要使用Marshaller的一种方法,但我现在不需要。 如何插入评论?

0 个答案:

没有答案