我有一个像这样在wadl中定义的类型(这是由wadl2java maven插件生成的ModelCriteria.java):
<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代码段:
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);
奖金:
附带说明一下,即使存在package-info.java,我仍然必须向ModelCriteria添加@XmlRootElement才能使其均匀传输。
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”)