2014-04-02 58 views

回答

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

更多信息

你可以參考下面的文章從我的博客了一個完整的例子:

+0

能莫西被配置成包裹數據自動在JAXBElement中?我的rest資源會返回數據並生成JSON和XML(即包裝該級別的數據會在JSON編組中產生一些問題)? –