既存の Java ドメイン モデル クラスに注釈を付けて XML スキーマを作成しました。現在、JAXB を使用して、restlet Web サービス内で受信した表現を非整列化しようとすると、何を試しても多くのエラーが発生します。私はrestletsとJAXBの両方に慣れていないので、両方を使用する適切な例の方向に私を向けると、これまでに見つけたものだけが役に立ちます:
私のエラーは次のとおりです。
restlet.ext.jaxb JaxbRepresentation を使用しようとすると:
@Override
public void acceptRepresentation(Representation representation)
throws ResourceException {
JaxbRepresentation<Order> jaxbRep = new JaxbRepresentation<Order>(representation, Order.class);
jaxbRep.setContextPath("com.package.service.domain");
Order order = null;
try {
order = jaxbRep.getObject();
}catch (IOException e) {
...
}
これから私は
java.io.IOException: Unable to unmarshal the XML representation.Unable to locate unmarshaller.
例外を取得しますjaxbRep.getObject()
そのため、代わりに次のコードを使用して、違いが生じるかどうかを確認する別のアプローチも試しました。
@Override
public void acceptRepresentation(Representation representation)
throws ResourceException {
try{
JAXBContext context = JAXBContext.newInstance(Order.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Order order = (Order) unmarshaller.unmarshal(representation.getStream());
} catch( UnmarshalException ue ) {
...
} catch( JAXBException je ) {
...
} catch( IOException ioe ) {
...
}
ただし、これにより、JAXBContext.newInstance への呼び出しが行われたときに次の例外も発生します。
java.lang.NoClassDefFoundError: javax/xml/bind/annotation/AccessorOrder
アドバイスをよろしくお願いします。