Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB generating JAXBElement<String> instead of String

I am using Apache CXF cxf-codegen-plugin Maven plugin to generate sources from WSDL file. Problem is that I get JAXBElement<String> generated instead of String. I have added the jaxb-bindings.xml file which looks like this:

<jaxb:bindings version="2.1"                xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">     <jaxb:globalBindings generateElementProperty="false"/> </jaxb:bindings> 

This should prevent JAXB to generate JAXBElement<String>. But it is not working I still have JAXBElement<String> generated instead of String.

My Maven plugin looks like this:

<plugin>     <groupId>org.apache.cxf</groupId>     <artifactId>cxf-codegen-plugin</artifactId>     <version>${cxf.runtime.version}</version>     <dependencies>         <dependency>             <groupId>org.apache.cxf</groupId>             <artifactId>cxf-rt-bindings-soap</artifactId>             <version>${cxf.runtime.version}</version>         </dependency>     </dependencies>     <executions>         <execution>             <id>generate-jaxb</id>             <phase>generate-sources</phase>             <configuration>                 <additionalJvmArgs>-Dfile.encoding=UTF8</additionalJvmArgs>                 <wsdlOptions>                     <wsdlOption>                         <wsdl>src/main/resources/wsdl/Cubiks.wsdl</wsdl>                         <extraargs>                             <extraarg>-b</extraarg>                             <extraarg>${basedir}/jaxb-bindings.xml</extraarg>                             <extraarg>-b</extraarg>                             <extraarg>${basedir}/jaxws-bindings.xml</extraarg>                             <extraarg>-exsh</extraarg>                             <extraarg>true</extraarg>                             <extraarg>-wsdlLocation</extraarg>                             <extraarg></extraarg>                         </extraargs>                     </wsdlOption>                     <wsdlOption>                         <wsdl>src/main/resources/wsdl/CubiksCallBackService.wsdl</wsdl>                         <extraargs>                             <extraarg>-b</extraarg>                             <extraarg>${basedir}/jaxws-bindings.xml</extraarg>                             <extraarg>-b</extraarg>                             <extraarg>${basedir}/jaxb-bindings.xml</extraarg>                             <extraarg>-exsh</extraarg>                             <extraarg>true</extraarg>                             <extraarg>-p</extraarg>                             <extraarg>com.cubiks.ws.callback</extraarg>                             <extraarg>-wsdlLocation</extraarg>                             <extraarg></extraarg>                         </extraargs>                     </wsdlOption>                 </wsdlOptions>             </configuration>             <goals>                 <goal>wsdl2java</goal>             </goals>         </execution>     </executions> </plugin> 

CXF version is 2.6.0. Does someone know where might be the problem?

EDIT

The XSD is very huge. This is the element which generating JAXBElement<String>

  <xs:complexType name="ServiceResponse">     <xs:sequence>       <xs:element minOccurs="0" name="RequestStatus" type="tns:RequestStatus"/>       <xs:element minOccurs="0" name="RequestStatusDescription" nillable="true" type="xs:string"/>     </xs:sequence>   </xs:complexType>   <xs:element name="ServiceResponse" nillable="true" type="tns:ServiceResponse"/> 

And the generated source is:

@XmlElementRef(name = "RequestStatusDescription", namespace = "http://www.cubiksonline.com/2009/08/AssessmentProvider", type = JAXBElement.class) protected JAXBElement<String> requestStatusDescription; 
like image 407
Paulius Matulionis Avatar asked Sep 20 '12 08:09

Paulius Matulionis


People also ask

How do you declare a JAXBElement of a string?

You can do the following: JAXBElement<String> jaxbElement = new JAXBElement(new QName("http://mycompany/services", "amount"), String. class, "Hello World"); There should also be a create method on the generated ObjectFactory class that will create this instance of JAXBElement with the appropriate info for you.

How do I get data from JAXBElement?

1 Answer. Show activity on this post. If getProject() returns the type JAXBElement<String> then getName() returns the name of the XML tag. To get the value of that element you need to call getValue() .

What is QName in JAXBElement?

QName getName() This method returns the xml element tag name. 3. Class getScope() This method returns scope of xml element declaration.


2 Answers

What I had to do is to wrap jaxb:globalBindings with another jaxb:bindings.

<jaxb:bindings version="2.0"                xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">     <jaxb:bindings>         <jaxb:globalBindings generateElementProperty="false"/>     </jaxb:bindings> </jaxb:bindings> 

Now everything is working, there is no JAXBElement<String> generated anymore.

like image 63
Paulius Matulionis Avatar answered Sep 24 '22 21:09

Paulius Matulionis


You can't have nillable and minoccurs together. Remove the minoccurs as it doesn't make sense for strings anyway.

like image 20
ramsinb Avatar answered Sep 25 '22 21:09

ramsinb