IBM Support

Top-Down (from a WSDL) generated JAX-WS web services client has a {Some}List associated Class
with no setter (only a get{Some}List)

Troubleshooting


Problem

Using IBM Rational Application Developer for WebSphere Software with WebSphere Application Server, a Top-Down (from a WSDL) generated JAX-WS web services client has a {Some}List associated Class with no setter (only a get{Some}List).

Symptom

No setter method in generated List Object class.

Cause

This behavior is expected and working as per JAX-WS/JAXB specification.

A Top-Down created JAX-WS (from a WSDL) bean has no Setter for some ArrayList object.

The Rational Application Developer JAX-WStools and the wsimport (the command line) behave the same way.

Resolving The Problem

The JAX-WS emitter creates a getter only for the ArrayList type. 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.

Note: This is why there is not a set method for some arbitrary "{someObject}" List property.

To add a new item (== set), do as follows (where "{someObject}" List includes ArrayList of someObject(s).):

get{someObject}().add(newItem);



Example of generated List Object class:

Here is An arbitrary ArrayList example of java like generated code.

Note: The generated code is arbitrary and generic and may not be perfect, but is intended to illustrate the principle.

Notice the generated comment associated with the generated getter for the element in the sequence/list, explaining why no setter in the example to follow:

"...

* This is why there is not a <CODE>set</CODE> method for the someService property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getSomeService().add(newItem);
* </pre>

.."

Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


//=== SomeServiceList.java
//
// Generated By:JAX-WS RI IBM 2.1.1 in JDK 6 (JAXB RI IBM JAXB 2.1.3 in JDK 1.6)
//
package somecompany.com.service;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import somecompany.com.service.SomeService;

/**
* <p>Java class for SomeServiceList complex type.
*
* <p>The following schema fragment specifies the expected content contained within this class.
*
* <pre>
* &lt;complexType name="SomeServiceList">
*   &lt;complexContent>
*     &lt;restriction base="{
http: //www.w3.org/2001/XMLSchema}anyType">
*       &lt;sequence>
*         &lt;element name="some_service" type="{
http: //somecompany.com.service}SomeService" maxOccurs="unbounded" minOccurs="0"/>
*       &lt;/sequence>
*     &lt;/restriction>
*   &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SomeServiceList", namespace = "
http: //somecompany.com.service", propOrder = {
   "someService"
})
public class SomeServiceList {

   @XmlElement(name = "some_service")
   protected List<SomeService> someService;
    /**
    * Gets the value of the someService property.
    *
    * <p>
    * 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 <CODE>set</CODE> method for the someService property.
    *
    * <p>
    * For example, to add a new item, do as follows:
    * <pre>
    *    getSomeService().add(newItem);
    * </pre>
    *
    *
    * <p>
    * Objects of the following type(s) are allowed in the list
    * {@link SomeService }
    *
    *
    */
   public List<SomeService> getSomeService() {
       if (someService == null) {
           someService = new ArrayList<SomeService>();
       }
       return this.someService;
    }

}

//--end SomeServiceList.java

Note: If there was another element in the above sequence for the complex type in the WSDL then the above code pattern would just be repeated for the generated code.



REFERENCES:

JAX-WS uses JAXB as its data binding. The reason for this behavior can be found in JAXB specification (below) on page 60 which provides an explanation and solution:

"...
Design Note: There is no setter method for a List property.
The getter returns the List by reference.
An item can be added to the List returned by the
getter method using an appropriate method defined on java.util.List.
Rationale for this design in JAXB 1.0 was to enable the implementation to wrapper
the list and be able to perform checks as content was added or removed from the
List.
..."



Java Architecture for XML Binding (JAXB) references:

JAXB 2.0 specification documentation:


The above WebSphere Application Server references refer to the JAXB 2.0 specifications:


Java API for XML Web Services (JAX-WS) references:
The above WebSphere Application Server references refer to Java-Sun JAX-WS 2.0 specifications.

[{"Product":{"code":"SSRTLW","label":"Rational Application Developer for WebSphere Software"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Web Services Development","Platform":[{"code":"PF033","label":"Windows"},{"code":"PF016","label":"Linux"}],"Version":"7.5.5.1;7.5.5;7.5.4;7.5.3;7.5.2;7.5.1;7.5","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
16 June 2018

UID

swg21440294