如何覆盖CXF中根类型的camelcase(wadl2java)
我有一个像这样在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>
将@XmlRootElement更改为@XmlRootElement(name =“ModelCriteria”)
链接地址: http://www.djcxy.com/p/51717.html上一篇: How to override camelcase on root types in CXF (wadl2java)
下一篇: JAXB namespace issue with extended annotated class' member