简体   繁体   中英

Cyclic references in jaxb and jax-ws

I'm writing client and server using jax-ws. One of my beans has cyclic reference to parent. To prevent cycles I've used @XMLId and @XMLIDRef annotations for my bean.

class A {
    // simple fields
    A parent;

    @XMLID
    String getID() {}

    @XMLIDRef
    A getParent() {}
}

Now then I'm returning bean as a result of web-method, everything works as I expect. But if I'm trying to pass this bean as input parameter to method via

A obj1 = //...
A obj2 = //...
obj2.setParent(obj1); 
ws.updateA(obj2); // web-method signature is updateA(A a)

(bean here was generated by wsimport tool)

I'm getting a strange behaviour. Client sends SOAP-request with obj2 where parent object exists only as reference in obj2. So, obj2 can't be normally decoded on server side and Parent property is null.

So, question is: "Where am I wrong and don't understand webservices?"
I expected that client will sends request with both object and parent object where they will be linked via referneces.

Funny as it seems, but your question has nothing to do with webservices, just with the marshaling /unmarshaling. Which is JAXB in your case I guess. I suggest you tag your question accordingly, I'm sure you'll get more relevant answers.

In the meantime please post the wsdl file (for the schema in it) and the complete source for this class A.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM