Moxy:marshall没有像@XmlRootElement这样的JAXB注释

时间:2014-04-02 12:25:42

标签: moxy

是否可以在不使用JAXB注释的情况下将所有Java POJO编组为XML而无需单独配置每个POJO类?

PS:上下文是泽西2的休息资源。

1 个答案:

答案 0 :(得分:1)

包括JAXB (JSR-222)在内的

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

了解更多信息

您可以参考我博客中的以下文章获取完整示例:

相关问题