ArrayOfXXX class out of soap input param of array type

I have a method with input param as Array. When I generate stub out of it creates List type.

But I want to know how to create a wrapper class around array type e.g. for class Apple it should create ArrayOfApple.

Is there any change needs to be done in class or any specific plugin need to be used?

Note: I am using JAXWS with Apache CXF implementation

Below is the sample code:

EmployeeService.java:

@WebService(endpointInterface="com.test.EmployeeService")
@SOAPBinding(style=Style.DOCUMENT)
public class EmployeeService {

    public String updateEmpRoles(@WebParam(name="EmpRoles")EmpRole[] empRoles) {
        return "SUCCESS";
    }
}

EmpRole.java :

@XmlType(name="EmpRole")
public class EmpRole {
    private String empRole;

    public String getEmpRole() {
        return empRole;
    }

    public void setEmpRole(String empRole) {
        this.empRole = empRole;
    }
}

After publishing, wsdl is getting generated as below -

enter image description here

But what I expect is WSDL should create ArrayOfEmpRole and it should wrap List<EmpRole>.

Kindly help

In short - I want something that Björn doesn't want in below link. (In his case, it's automatically creating ArrayOfXXX, this is what I need) - Arrays in SOAP method Parameters generated via JAX-WS?

728x90

1 Answers ArrayOfXXX class out of soap input param of array type

I would switch from Code first to a Contract first approach which means start with the WSDL and generate a stub using wsdl2java from it. This way you can ensure that the WSDL looks like the way you want.

If you want to stick to the current approach, the easiest way to achieve a wrapper is probably to introduce another class.

4 months ago