我有一个像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>
外出拦截器记录以下内容:
Payload: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><modelCriteria xmlns="http://www.example.com/services/v2"><modelNumber>MODELNUM</modelNumber></modelCriteria>
在这种情况下,由于我正在使用的服务(我无法解决这个问题),我需要根类型为 ModelCriteria ,而不是 modelCriteria 。有没有办法解决这个问题,并保持代码复杂性?这是我的例子:
ModelCriteria片段:
@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,我仍然需要将@XmlRootElement添加到ModelCriteria以使其均匀传输。
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>
答案 0 :(得分:2)
将@XmlRootElement更改为@XmlRootElement(name =“ModelCriteria”)