I'm having an issue with jaxb. One of my elements is requiring me to set a JAXBElement<String>
, instead of just a String
. I know that a solution to this is to change the xsd, as discussed here JAXB generating JAXBElement<String> instead of String, but the xsd was provided by the vendor, and we can't convince them to change it.
我遇到了jaxb的问题。我的一个元素是要求我设置一个JAXBElement
Apparently another solution is to specify a property <jaxb:globalBindings generateElementProperty="false">
, which would turn off the JAXBElements
globally, which is also not what we want.
显然,另一个解决方案是指定一个属性
According to this page, it should be possible to set generateElementProperty="false"
locally in a <jaxb:property>
customization. How can I do that in a bindings file? The only examples I can find (like this) seem to be setting it directly in the xsd -- and if I could change that, I'd just remove the minOccurs.
根据此页面,应该可以在
My current bindings file looks like this:
我当前的绑定文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<jxb:bindings version="1.0" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema" jxb:extensionBindingPrefixes="xjc" xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
<jxb:bindings schemaLocation="../XXXPrivateService.xsd" node="/xs:schema">
<jxb:globalBindings>
<xjc:noValidator />
<xjc:serializable />
</jxb:globalBindings>
<jxb:schemaBindings>
<jxb:package name="com.XXX.YYYY.xsd.XXXprivateservice">
<jxb:javadoc><![CDATA[<body>TODO</body>]]></jxb:javadoc>
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../XXXPrivateService_1_2.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="com.XXX.YYYY.xsd.XXXprivateservice.two">
<jxb:javadoc><![CDATA[<body>TODO</body>]]></jxb:javadoc>
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../XXXPrivateService_1_2_3.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="com.XXX.YYYY.xsd.XXXprivateservice.three">
<jxb:javadoc><![CDATA[<body>TODO</body>]]></jxb:javadoc>
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../XXXPrivateService_1_2_3_4.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="com.XXX.YYYY.xsd.XXXprivateservice.four">
<jxb:javadoc><![CDATA[<body>TODO</body>]]></jxb:javadoc>
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../XXXPrivateService_1_2_3_4_5.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="com.XXX.YYYY.xsd.XXXprivateservice.five">
<jxb:javadoc><![CDATA[<body>TODO</body>]]></jxb:javadoc>
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../XXXPrivateService_1_2_3_4_5_6.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="com.XXX.YYYY.xsd.XXXprivateservice.six">
<jxb:javadoc><![CDATA[<body>TODO</body>]]></jxb:javadoc>
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="../XXXPrivateService_1_2_3_4_5_6_7.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="com.XXX.YYYY.xsd.XXXprivateservice.seven">
<jxb:javadoc><![CDATA[<body>TODO</body>]]></jxb:javadoc>
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>
The offending portion of the XSD looks like this:
XSD的违规部分如下所示:
<xs:element name="PayWithPointsRedemption">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="requestSourceId" type="xs:unsignedInt"/>
<xs:element minOccurs="0" name="rewardsAccountId" type="xs:unsignedInt"/>
<xs:element minOccurs="0" name="XXXReferenceId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="externalChannelCode" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="payWithPointsRedemptionDetails" nillable="true" type="q4:ArrayOfPayWithPointsRedemptionDetail" xmlns:q4="http://ZZZZZ.YYYY.com/XXXRewards"/>
</xs:sequence>
</xs:complexType>
</xs:element>
1 个解决方案
#1
3
You should be able to set it locally in your external binding like this
您应该能够像这样在外部绑定中本地设置它
<jxb:bindings schemaLocation="xyz.xsd"
node="/xs:schema">
<jxb:schemaBindings>
<!-- ... -->
</jxb:schemaBindings>
<jxb:bindings
node="/xs:schema/xs:element[@name='PayWithPointsRedemption']/xs:complexType/xs:sequence">
<jxb:property generateElementProperty="false" />
</jxb:bindings>
</jxb:bindings>
Make sure the XPath expression in jxb:bindings
matches!
确保jxb:bindings中的XPath表达式匹配!
#1
3
You should be able to set it locally in your external binding like this
您应该能够像这样在外部绑定中本地设置它
<jxb:bindings schemaLocation="xyz.xsd"
node="/xs:schema">
<jxb:schemaBindings>
<!-- ... -->
</jxb:schemaBindings>
<jxb:bindings
node="/xs:schema/xs:element[@name='PayWithPointsRedemption']/xs:complexType/xs:sequence">
<jxb:property generateElementProperty="false" />
</jxb:bindings>
</jxb:bindings>
Make sure the XPath expression in jxb:bindings
matches!
确保jxb:bindings中的XPath表达式匹配!