相关疑难解决方法(0)

没有由JAXB生成的@XmlRootElement

我正在尝试从FpML(Finanial产品标记语言)4.5版生成Java类.生成了大量代码,但我无法使用它.尝试序列化一个简单的文档,我得到这个:

javax.xml.bind.MarshalException
  - with linked exception: [com.sun.istack.SAXException2: unable
  to marshal type
  "org.fpml._2008.fpml_4_5.PositionReport"
  as an element because it is missing an
  @XmlRootElement annotation]
Run Code Online (Sandbox Code Playgroud)

实际上没有类有@XmlRootElement注释,所以我可以做错什么?我将xjc(JAXB 2.1)指向fpml-main-4-5.xsd,然后包含所有类型.

java jaxb xjc fpml

199
推荐指数
14
解决办法
24万
查看次数

如何使用JAXB为XML中的空元素生成结束标记

我正在使用JAXB生成XML.但是JAXB正在生成一个空标签.但我的客户想要单独的空标签.我知道两者都是平等但他不同意我的看法.请任何人建议解决方案.谢谢.

示例代码:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "currencyCode",
    "discountValue",
    "setPrice",
    "spendLowerThreshold",
    "spendUpperThreshold",
    "discountApportionmentPercent",
    "discountApportionmentValue"
})
@XmlRootElement(name = "countryData")
public class CountryData {
    protected String currencyCode;
    protected String discountValue = "";
    protected String setPrice = "";
    protected String spendLowerThreshold = "";
    protected String spendUpperThreshold = "";
    protected String discountApportionmentPercent = "";
    protected String discountApportionmentValue = "";

    // Setters and Gettres
}
Run Code Online (Sandbox Code Playgroud)

实际产量:

<currencyCode>GBP</currencyCode>
<discountValue/>
<setPrice/>
<spendLowerThreshold/>
<spendUpperThreshold/>
<discountApportionmentPercent>0.0</discountApportionmentPercent>
<discountApportionmentValue/>
Run Code Online (Sandbox Code Playgroud)

预期产出:

<currencyCode>GBP</currencyCode>
<discountValue></discountValue>
<setPrice></setPrice>
<spendLowerThreshold></spendLowerThreshold>
<spendUpperThreshold></spendUpperThreshold>
<discountApportionmentPercent>0.0</discountApportionmentPercent>
<discountApportionmentValue></discountApportionmentValue>
Run Code Online (Sandbox Code Playgroud)

编组代码:

try …
Run Code Online (Sandbox Code Playgroud)

java xml jaxb marshalling java-6

7
推荐指数
1
解决办法
7711
查看次数

标签 统计

java ×2

jaxb ×2

fpml ×1

java-6 ×1

marshalling ×1

xjc ×1

xml ×1