是否可以在不使用JAXB注释的情况下将所有Java POJO编组为XML而无需单独配置每个POJO类?
PS:上下文是泽西2的休息资源。
答案 0 :(得分:1)
MOXy个实现不需要任何注释。如果没有@XmlRootElement
注释,则需要将对象包装在JAXBElement
的实例中。
JAXBContext jc = JAXBContext.newInstance(Foo.class);
Foo foo = new Foo();
JAXBElement<Foo> je = new JAXBElement(new QName("root-element"), Foo.class, foo);
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal(je, System.out);
了解更多信息
您可以参考我博客中的以下文章获取完整示例: