除了CDATA之外,如何使用编组JAXB在每个标记之前插入注释?
我有以下代码:除了CDATA之外,如何使用编组JAXB在每个标记之前插入注释?,jaxb,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.se
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);
}
也许我需要使用马歇尔勒的方法,但我现在不需要。
如何插入注释?请参阅。也许这就是你要找的。谢谢!但我看到了