我有2个XSD模式文件,这些文件已使用XJC转换为POJO。当我尝试将XML字符串解组到类时,我发现变成ref
的{{1}}元素,尤其是在包含列表(from)的类中并没有完全解组。他们引用了正确的类型和值,但并不仅仅是展现自己。我已经阅读了代码中的某些表示法,指出其中的一些是实时列表的@XmlElementRef
,而不是快照。我最终尝试将未编组的XML转换为JSON。这是当前行为(摘要):
.XSD
@link
ControlTransaction.java类
<xs:element name="ControlTransaction">
<xs:complexType>
<xs:sequence>
<xs:element ref="ixretail:ReasonCode"/>
<xs:choice>
<xs:element ref="dtv:SystemCycleType"/>
<xs:element ref="ixretail:NoSale"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
-IntelliJ突出显示了如何从未使用过吸气剂和吸气剂
Transaction.java-ControlTransaction父级
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"reasonCode",
"systemCycleTypeOrNoSale"
})
@XmlRootElement(name = "ControlTransaction")
public
class ControlTransaction {
@XmlElement(name = "ReasonCode", required = true)
protected String reasonCode;
@XmlElementRefs({
@XmlElementRef(name = "NoSale", namespace = "http://www.nrf-arts.org/IXRetail/namespace/", type = JAXBElement.class, required = false),
@XmlElementRef(name = "SystemCycleType", namespace = "http://www.datavantagecorp.com/xstore/", type = JAXBElement.class, required = false)
})
protected JAXBElement<String> systemCycleTypeOrNoSale;
/**
* Gets the value of the reasonCode property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getReasonCode() {
return reasonCode;
}
/**
* Sets the value of the reasonCode property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setReasonCode(String value) {
this.reasonCode = value;
}
/**
* Gets the value of the systemCycleTypeOrNoSale property.
*
* @return
* possible object is
* {@link JAXBElement }{@code <}{@link String }{@code >}
* {@link JAXBElement }{@code <}{@link String }{@code >}
*
*/
仅包含一个获取
示例XML
public List<Object> getForeignCurrencyExchangeRateOrTenderExchangeOrTimeClockTransaction() {
if (foreignCurrencyExchangeRateOrTenderExchangeOrTimeClockTransaction == null) {
foreignCurrencyExchangeRateOrTenderExchangeOrTimeClockTransaction = new ArrayList<Object>();
}
return this.foreignCurrencyExchangeRateOrTenderExchangeOrTimeClockTransaction;
}
JSON输出显示值,但不是简单的{“ key”:“ value”}
<ControlTransaction>
<ReasonCode>Store Open</ReasonCode>
<dtv:SystemCycleType>Store Open</dtv:SystemCycleType>
</ControlTransaction>
如何确保在解组后后续JSON包含k:v对?值在那里并且类型已知,但是输出太冗长。它是一个可以添加到绑定文件中的选项,还是带有逻辑的其他选项。我的XSD中有太多示例无法创建定制适配器,因此我希望可以在XJC,JAXB pojo创建步骤中解决此问题。预先感谢。