Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

3 counts of IllegalAnnotationExceptions

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 base TestCase 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.

like image 354
Sami Avatar asked Jul 20 '10 17:07

Sami


1 Answers

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() {
}
like image 72
bdoughan Avatar answered Sep 30 '22 10:09

bdoughan