我的xsd文件中有以下条目:
<xsd:element name="isCaseCreationAllowedResponse">
<xsd:complexType>
<xsd:sequence>
....
<xsd:element maxOccurs="1" minOccurs="0" name="operatorNote" type="xsd:string">
</xsd:element>
....
<xsd:sequence id="allowCaseWithNewContract">
<xsd:element maxOccurs="1" minOccurs="1" name="allowCaseWithNewContract" type="xsd:boolean">
</xsd:element>
<xsd:choice minOccurs="0">
<xsd:element name="validationError" type="mnp:ErrorType"/>
<xsd:element name="internalError" type="mnp:ErrorType"/>
<xsd:element name="businessError" type="mnp:ErrorType"/>
<xsd:element name="externalError" type="mnp:ErrorType"/>
</xsd:choice>
</xsd:sequence>
....
<xsd:sequence id="allowCaseWithExistingContract">
<xsd:element maxOccurs="1" minOccurs="1" name="allowCaseWithExistingContract" type="xsd:boolean">
</xsd:element>
<xsd:choice minOccurs="0">
<xsd:element name="validationError" type="mnp:ErrorType"/>
<xsd:element name="internalError" type="mnp:ErrorType"/>
<xsd:element name="businessError" type="mnp:ErrorType"/>
<xsd:element name="externalError" type="mnp:ErrorType"/>
</xsd:choice>
</xsd:sequence>
....
</xsd:sequence>
</xsd:complexType>
</xsd:element>
由于顺序生成的java文件顺序如下:
public class OperationResponse {
protected List<JAXBElement<?>> content;
public List<JAXBElement<?>> getContent() {
if (content == null) {
content = new ArrayList<JAXBElement<?>>();
}
return this.content;
}
}
有没有办法配置CXF / JAXB / JAXWS来生成java类中的字段,而不是这个不直观的列表。
无法修改WSDL,因此只能配置wsdl2java。我在jaxb绑定中尝试过xjc:simple,但它并没有像我期望的那样工作。
我正在使用带有maven cxf-codegen-plugin的CXF 2.7.5。
使用xjc我有以下注释
<xsd:schema>
<xsd:annotation>
<xsd:appinfo>
<jaxb:globalBindings generateValueClass="false">
<xjc:simple />
</jaxb:globalBindings>
</xsd:appinfo>
</xsd:annotation>
</xsd:schema>
生成的类:
public class OperationResponse {
protected String operatorNote;
....
protected boolean allowCaseWithNewContract;
@XmlElementRefs({
@XmlElementRef for allowCaseWithExistingContract
@XmlElementRef for validationError and so on
})
protected List<JAXBElement<?>> validationErrorsAndAllowCaseWithExistingContractsAndInternalErrors;
}
上面配置的Xjc生成了另一个JAXBelement列表,这就是为什么它没有按照我的预期工作(删除所有JAXBElement列表并用包含正确字段的对象替换它们)。
修改
使用以下配置:
<xsd:appinfo>
<jaxb:globalBindings generateElementProperty="false" fixedAttributeAsConstantProperty="true" choiceContentProperty="true">
</jaxb:globalBindings>
<jaxb:bindings>
<jaxb:bindings node="//xsd:element[@name='isContractSigningAllowedResponse']/xsd:complexType/xsd:sequence/xsd:sequence[@id='allowStandardContract']">
<jaxb:property name="allowStandardContractSequence"/>
</jaxb:bindings>
<jaxb:bindings node="//xsd:element[@name='isContractSigningAllowedResponse']/xsd:complexType/xsd:sequence/xsd:sequence[@id='allowOneVisitContract']">
<jaxb:property name="allowOneVisitContractSequence" />
</jaxb:bindings>
<jaxb:bindings node="//xsd:element[@name='isCaseCreationAllowedResponse']/xsd:complexType/xsd:sequence/xsd:sequence[@id='allowCaseWithNewContract']">
<jaxb:property name="allowCaseWithNewContractSequence"/>
</jaxb:bindings>
<jaxb:bindings node="//xsd:element[@name='isCaseCreationAllowedResponse']/xsd:complexType/xsd:sequence/xsd:sequence[@id='allowCaseWithExistingContract']">
<jaxb:property name="allowCaseWithExistingContractSequence" />
</jaxb:bindings>
</jaxb:bindings>
</xsd:appinfo>
我从wsdl2java生成了类似的东西:
public class IsCaseCreationAllowedResponse {
@XmlElement(required = true)
protected String msisdn;
protected String operator;
protected String operatorNote;
protected String routingNumber;
@XmlElementRefs({
@XmlElementRef(name = "internalError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
@XmlElementRef(name = "externalError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
@XmlElementRef(name = "validationError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
@XmlElementRef(name = "businessError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
@XmlElementRef(name = "allowCaseWithNewContract", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class)
})
protected List<JAXBElement<?>> allowCaseWithNewContractSequence;
@XmlElementRefs({
@XmlElementRef(name = "validationError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
@XmlElementRef(name = "externalError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
@XmlElementRef(name = "businessError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
@XmlElementRef(name = "internalError", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class),
@XmlElementRef(name = "allowCaseWithExistingContract", namespace = "http://playmobile.pl/common/mnpm/schema", type = JAXBElement.class)
})
protected List<JAXBElement<?>> allowCaseWithExistingContractSequence;
protected String mnpmContractId;
protected String contractNumber;
protected String ccbsAccountId;
protected Boolean fixedNumber;
protected String description;
@XmlElement(required = true)
protected OperatorListType activeOperators;
}
我必须在内部序列中添加一些id才能正确绑定。
有没有办法将 allowCaseWithExistingContractSequence 和 allowCaseWithNewContractSequence 列入具有正确字段的某些对象?
答案 0 :(得分:1)
我在绑定文件中有以下设置,摆脱了JAXBElements并得到了很好的字段:)
<jaxb:globalBindings generateElementProperty="false" fixedAttributeAsConstantProperty="true" choiceContentProperty="true">
如果您不想在1个字段中选择元素(...或......或......),请将其设置为 false 。