Showing posts with label JAXB. Show all posts
Showing posts with label JAXB. Show all posts

Tuesday, March 18, 2014

Resolve java.util.List is an interface, and JAXB can't handle interfaces.

Working on a Web service, I caught this error while deploying:

Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
java.util.List is an interface, and JAXB can't handle interfaces.
this problem is related to the following location:
at java.util.List

The problem comes from my WebMethod where I am returning a List<List<Car>>.  JAXB don't know how to handle this. So I have found a Solution where I define a new bean conating the List:


Class Cars{
    private List<car> cars;
...

}

So my WebMethod will return List<Cars>. This new bean resolves the problem. Make Sure also that the attribute is private (or don't put it at all, by default it will be private) otherwise you can have an error :
Class has two properties of the same name. See this post.




Ref : https://stackoverflow.com/questions/298733/java-util-list-is-an-interface-and-jaxb-cant-handle-interfaces

Wednesday, February 26, 2014

Resolved Error: Class has two properties of the same name this problem is related to the following location

I have created a bean which I will return in a web service. When deploying on JBoss Eap 6, I have detected this error:

 Class has two properties of the same name  this problem is related to the following location

The source of the problem is that I have both XmlAccessType.FIELD and getters and setters.
The solution is then to create constructors (the default one and with all fields) and remove all the setters. Now it is working.

This is not a good solution !!
So what I have recently discovered thanks to a friend (Ridwan), is that I was putting the attributes of the bean as PUBLIC and having also the getter. In fact, for a bean, the attributes should be PRIVATE (If you don't put the visibility it will be private by default).
The nice Solution is thus to do:

Class Car{

   private String model;
  
   public Car(){
        super();
   }

   public String getModel(){
       return this.model;
   }

   public void setModel(String model){
      this.model =  model;
   }
   
}

Articles les plus consultés