views:

1596

answers:

2

Hi, I have the following problem: I'm using the wsimport ant task to create a webservice client (for salesforce.com). Everything's working fine but the generated classes all use this strange JAXBElement class for all bean properties.

Eg:

public void setLastName(JAXBElement<String> value) {
    this.lastName = ((JAXBElement<String> ) value);
}

public JAXBElement<String> getCountry() {
    return country;
}

Instead of wrapping all classes in JAXBElement I'd like to have simple methods like setLastName(String newLastName). That's how I'm calling the wsimport task.

<wsimport debug="false" verbose="false" keep="${keep}" 
   extension="${extension}" destdir="${tmp.metro}" 
   wsdl="${licensing.wsdl}" 
   sourcedestdir="${licensingws.generated.src}"

   >

   <binding dir="${basedir}/etc" includes="${client.binding}"   
     />
    <arg value="-B-XautoNameResolution" />

  </wsimport>

The task is defined this way:

Does anybody know what I have to set so that wsimport generates the classes the way I want? Thanks a lot in advance!!!

+1  A: 

You will have to customize the binding.

rodrigoap
+2  A: 

The reason for using JAXBElement wrappers in the generated beans is probably, that the WSDL declares the field to be both optional and nillable. To distinguish between "not present" and "present, but null", the String type cannot be used directly, since the String in both cases would be null.

If you don't need to distinguish between the two situations, you can configure the code generator to use the String type instead. I'm not 100% sure how to do this with the ant task, but you'll probably find the relevant information in the ant task documentation.

jarnbjo
thanks, I solved it using this binding file:<jxb:bindings version="2.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <jxb:globalBindings generateElementProperty="false"/> </jxb:bindings>declared in build.xml as follows:<wsimport ... > <binding dir="." includes="simple-binding.xjb" /> </wsimport>
MisterY