views:

56

answers:

1

I have never used JAXB before. I am working on a test harnesses project. I have around 20 different testcases. when i run my test i get this error.

my structure is like

A is the bestTestCase class.

B extends A.

C extends B.

Base Class A:

public Class A {
  public A(String t){
     testName = t;
  }

  private String aData;
  private String testName;
  public void setAData(String a){
     aData = a;
  }

  public void getAData(){
     return aData;
  }

  public void setTestName(String t){
     testName = t;
  }

  public void getTestName(){
     return testName;
  }
}

Class B:

public Class B extends A{ 
   public B(String testName){
      super(testName);
   }

   private String bData;
   public void setBData(String b){
      bData = b.trim();
   }
   public String getData(){
      return bData;
   }       
}

Class C:

@XmlRootElement(name="C")
public Class C extends B{
    public C(String testName){
        super(testName);
    }

    private String cData;
    public void setCData(String c){
        cData = c;
    }
    public String getCData(){
        return cData;
    }
}

and for unmarshalling my xml files i wrote

public C unmarshall(C test, String dir){
    try {
        JAXBContext jc = JAXBContext.newInstance(c.getClass);
        Unmarshaller u = jc.createUnmarshaller();

        test = (C)u.unmarshal(new FileInputStream(dir));
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

    return test;
 }

my xml file looks like:

<C>
   <aData> aaaa </aData>
   <bData> bbbb </bData>
   <cData> cccc </cData>
</C>

when i run my code i get 3 counts of IllegalAnnotationException.

+1  A: 

The IllegalAnnotationExceptions are due to you not having default zero-arg constructors on A, B, and C.

Add to A:

public A() {
}

Add to B:

public B() {
}

And add to C:

public C() {
}
Blaise Doughan