How to override camelcase on root types in CXF (wadl2java)

I have a type defined in a wadl like so (This is from the ModelCriteria.java generated by wadl2java maven plugin):

<complexType name="ModelCriteria">
  <complexContent>
    <extension base="{http://www.example.com/services/v2}AbstractSearchCriteria">
      <sequence>
        <element name="modelNumber" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
        <element name="hasAssociation" type="{http://www.w3.org/2001/XMLSchema}boolean" minOccurs="0"/>
        <element name="manufacturerName" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
        <element name="type" type="{http://www.example.com/services/v2}ModelType" minOccurs="0"/>
      </sequence>
    </extension>
  </complexContent>
</complexType>

The out-going interceptor logs the following:

Payload: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><modelCriteria xmlns="http://www.example.com/services/v2"><modelNumber>MODELNUM</modelNumber></modelCriteria>

In this case, because of the service I am using (which I can't fix to not care about case), I NEED the root type to be ModelCriteria , not modelCriteria . Is there any way of fixing this, and keeping code complexity down? Here is my example:

ModelCriteria snippet:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ModelCriteria", propOrder = {
    "modelNumber",
    "hasAssociation",
    "manufacturerName",
    "type"
})
@XmlRootElement
public class ModelCriteria
    extends AbstractSearchCriteria
{

ModelCriteriaTest snippet:

    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress("https://example.com/services/v2/rest");
    bean.setUsername(...);
    bean.setPassword(...);
    bean.setResourceClass(ModelRestService.class);

    bean.getOutInterceptors().add( new org.apache.cxf.interceptor.LoggingOutInterceptor() );

    ModelRestService model = bean.create(ModelRestService.class);

    ModelCriteria mc = oFact.createModelCriteria();
    mc.setModelNumber("CFK");

    FindModelResult fmResult = model.findByCriteria(mc);

BONUS: As a side note, even though package-info.java is present, I still have to add @XmlRootElement to ModelCriteria to get it to even transmit.

Snippet of WADL:

<application 
         xmlns="http://wadl.dev.java.net/2009/02" 
         xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <grammars>
     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
                xmlns:tns="http://www.example.com/services/v2" 
                attributeFormDefault="unqualified" 
                elementFormDefault="qualified"            
                targetNamespace="http://www.example.com/services/v2">

       ... other types ... 

       <xs:element name="ModelCriteria" type="tns:ModelCriteria"/> 
     </xs:schema>
   </grammars>
   <resources> ... </resources>
 </application> 

将@XmlRootElement更改为@XmlRootElement(name =“ModelCriteria”)

链接地址: http://www.djcxy.com/p/51718.html

上一篇: 如何从JAXB编组XML文件中删除xmlns:xsi和xsi:type

下一篇: 如何覆盖CXF中根类型的camelcase(wadl2java)