How do I prevent JAXBElement<String> from being generated in a CXF Web Service client?

JavaWcfWeb ServicesJaxbCxf

Java Problem Overview


I'm trying to create a web service client using CXF to consume a WCF web service. When I use wsdl2java it generates objects with JAXBElement types instead of String.

I read about using a jaxb bindings.xml file to set generateElementProperty="false" to try to fix the problem, but the web service I'm consuming contains 7 imported schemas.

How can I specify the generateElementProperty="false" on all seven schemas, or is there a way to apply it to all schemas?

Java Solutions


Solution 1 - Java

You have to create a binding file as below, this will get applied globally and use it as wsdl2java - b "bindings.txt" "wsdl"

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

Solution 2 - Java

Note that in my case I had to use <xjc:simple in my jaxb binding file to get rid of the JAXBElement request and response wrappers in the @Endpoint:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" elementFormDefault="qualified" attributeFormDefault="unqualified" jaxb:extensionBindingPrefixes="xjc" jaxb:version="2.1">
	<xs:annotation>
		<xs:appinfo>
			<jaxb:globalBindings>
				<xjc:simple /><!-- it did only work after adding this -->
			</jaxb:globalBindings>
		</xs:appinfo>
	</xs:annotation>
</xs:schema>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionScArcher2View Question on Stackoverflow
Solution 1 - JavapriyaView Answer on Stackoverflow
Solution 2 - JavayglodtView Answer on Stackoverflow