28

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!!!

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
MisterY
  • 445
  • 1
  • 6
  • 8

4 Answers4

31

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
  • 33,923
  • 7
  • 70
  • 94
  • 7
    thanks, I solved it using this binding file: declared in build.xml as follows: – MisterY Feb 02 '10 at 07:35
  • 1
    To configure the jaxws bindings file, see this link: http://metro.1045641.n5.nabble.com/Generated-Code-with-minOccurs-0-and-nillable-true-contains-JAXBElement-tp1063625p1063626.html – GWTNewbie Aug 22 '14 at 13:00
4

You will have to customize the binding.

rodrigoap
  • 7,405
  • 35
  • 46
4

I have faced similar problem.

I have used below binding XML while ceiling wsimport :with reference of this link.

Binding file

<jaxb:bindings version="2.1" 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
   <jaxb:globalBindings generateElementProperty="false"/> 
</jaxb:bindings>

Sample wsimport command:

wsimport -keep  <WSDL_location>  -b employerServiceWSD
L_binding.xjb

Note : employerServiceWSDL_binding.xjb contain of above binding xml entry.

Hope it will work for other also.

Gautam
  • 3,707
  • 5
  • 36
  • 57
0

Resolution is to use 'Binding' file, and add converter for each data types. Below is my example, you can modify the javaType as per your WSDL. Also, tutorials point described methods how to pass from wsdl -> java POJO properly.

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" 
               jaxb:version="1.0"
               xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc">
    <jaxb:globalBindings generateElementProperty="false">
    <jaxb:serializable uid="1"/>
    <jaxb:javaType name="java.util.Calendar" xmlType="xs:dateTime"
        parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime"
        printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/> 
    <jaxb:javaType name="java.util.Calendar" xmlType="xs:date"
                parseMethod="javax.xml.bind.DatatypeConverter.parseDate" 
                printMethod="javax.xml.bind.DatatypeConverter.printDate" />
    <jaxb:javaType name="java.util.Calendar" xmlType="xs:time"
                parseMethod="javax.xml.bind.DatatypeConverter.parseTime" 
                printMethod="javax.xml.bind.DatatypeConverter.printTime" />
 </jaxb:globalBindings>
</jaxb:bindings>
mandrin
  • 1
  • 2