Castor Error:不支持前向引用

时间:2014-09-10 21:39:08

标签: java xml castor

Castor试图将我的对象编组为XML并抛出错误,指出“不支持前向引用” 我有3个java类

public class RandomTransactionRequest extends TransactionRequest {
   public RandomTransactionRequest() { super("location") }
}

public class TransactionRequest extends ServiceRequest {
   private StatusObject status;
   public TransactionRequest (String destination) {
      setDestination(destination);
   }
}

public class ServiceRequest {
     private String destination;
     public String getDestination(){ return destination; }
     public void setDestination(String destination) { this.destination = destination; }
 }

我期待XML如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<REQUEST>
  <DEST>location</DEST>
  <STATUS_FIELDS>
    <STATUS>
      <INIT_STAT>incomplete</INIT_STAT>
      <FIN_STAT>complete</FIN_STAT>
    </STATUS>
  </STATUS_FIELDS>
</REQUEST>

A类的我的Castor映射如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<mapping>
    <class name="com.package.requests.RandomTransactionRequest" extends="com.package.requests.TransactionRequest">
    <map-to xml="REQUEST"/>
</class>
<class name="com.package.requests.TransactionRequest" extends="com.package.requests.ServiceRequest">
    <field name="status" type="com.package.objects.StatusObject">
        <bind-xml name="STATUS" location="APP"/>
    </field>
</class>
<class name="com.package.requests.ServiceRequest" >
    <field name="destination" type="java.lang.String">
        <bind-xml name="DEST" />
    </field>
</class>
<class name="com.package.objects.StatusObject" >
    <field name="initialStatus" type="java.lang.String">
        <bind-xml name="INIT_STAT"/>
    </field>
    <field name="finalStatus" type="java.lang.String">
        <bind-xml name="FIN_STAT"/>
    </field>
</class>
</mapping>

收到错误:

  

在类com.package.requests.RandomTransactionRequest中找不到扩展类org.exolab.castor.mapping.xml.ClassMapping@48584858的类描述符 - 不支持转发引用

1 个答案:

答案 0 :(得分:0)

我缺少的是向TransactionRequest添加默认构造函数。 Castor需要能够实例化您正在映射的类,并且需要默认构造函数来执行此操作。

我的最后一堂课看起来像这样:

 public class TransactionRequest extends ServiceRequest {
   private StatusObject status;

   public TransactionRequest () {}   /* NEEDED DEFAULT CONSTRUCTOR */

   public TransactionRequest (String destination) {
      setDestination(destination);
   }
 }