简体   繁体   中英

Generated web services client classes with no setters

I've created a client for SOAP web service, but in the generated code some classes miss setter methods.

WSDL for the objects looks like:

<xsd:complexType name="UserDefinedFieldArray">
<xsd:sequence>
<xsd:element name="userDefinedField" minOccurs="0" maxOccurs="unbounded"  
           type="ns0:UserDefinedField"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="UserDefinedField">
<xsd:sequence>
<xsd:element name="fieldName" type="xsd:string"/>
<xsd:element name="fieldValue" type="xsd:string"/>
<xsd:element name="listId" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>

Those objects have only setXXX(), and Java Docs insist on this:

"This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make to the returned list will be present inside the JAXB object. This is why there is not a set method for the testSuiteUdfs property. For example, to add a new item, do as follows: getTestSuiteUdfs().add(newItem); "

Though my logic says to me, that the updated list cannot get to the server until u send it there?

The only related thing I managed to find: http://www-01.ibm.com/support/docview.wss?uid=swg21440294 . But it was not helpful at all.

Can anyone, please, tell me which way to dig? Cause I don't understand at all how this is supposed to work. Thanks!

Updating a domain object mapped by JAXB does not cause communication with the server. JAXB (JSR-222) is a standard for converting objects to/from XML. It is leveraged by JAX-WS (SOAP) and JAX-RS (RESTful) frameworks to produce/consume messages sent over the wire between clients an servers.

UPDATE

" any modification you make to the returned list will be present inside the JAXB object."

All this means is that the List you get is the real List and not a copy. You can test this out with the following code:

System.out.println(customer.getPhoneNumbers().size());  // returns x
customer.getPhoneNumbers().add(new PhoneNumber());
System.out.println(customer.getPhoneNumbers().size());  // returns x + 1

use @XmlElementWrapper on the element you want to expose as list or array type. Make sure you set name for @XmlElement, which the generated stub code in the client don't confuse the class names.

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