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;
}
}
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;
}
}
This comment has been removed by a blog administrator.
ReplyDelete