I created some classes using JAXB XJC. They follow this pattern (some properties with getters and setters and xml annotations):
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "School", propOrder = {
"info",
"students"
})
public class School {
@XmlElement(name = "Info", required = true)
protected Info info;
@XmlElement(name = "Students", required = true)
protected List<Student> students;
public Info getInfo(){ return info;}
public void setInfo(Info value){ info = value};
public List<Students> getStudents(){
if (students == null) {
students = new ArrayList<Student>();
}
return students;
}
public void setStudents(List<Student> elements){
if (students == null) {
students = new ArrayList<Student>();
}
students.addAll(elements);
}
When I use java.beans.Introspector.getBeanInfo
and BeanInfo.getPropertyDescriptors
to get the class BeanInfo I can see that my School
class has a property called students
with the WriteMethod
being setStudents(List)
. I believe that the BeanInfo of this class was generated following the default rules of Bean, according to Java Beans specification:
If we discover a matching pair of
get<PropertyName>
andset<PropertyName>
methods that take and return the same type, then we regard these methods as defining a read-write property whose name will be<propertyName>
.
So, how can I change the BeanInfo of this class? More precisely, I want to set the WriteMethod
of the property students
to be another method that does not follow the default rule mentioned above (it would be public void setStudent (Student student){...}
). How can I do this?
Only to make sure it is clear... When I use java.beans.Introspector.getBeanInfo
and BeanInfo.getPropertyDescriptors
to get the class BeanInfo I want to see that my School
class has the property students
with the WriteMethod
being my new set method (setStudents(Student)
that does not follow the default rule).
I saw some things here, but it wasn't enough for me...
Thank you!