I have a class like this:
import java.util.List;
import java.util.String;
import javax.xml.bind.annotation.XmlType;
@XmlType
public class Foo {
private List<Foo> compound;
private String bar;
// private method used internally to know
// if this is a compound instance
private boolean isCompound() {
return compound != null && compound.size() != 0;
}
// public setter for compound instance var
public void setCompound(List<Foo> compound) {
this.compound = compound;
}
// public getter for compound instance var
public List<Foo> getCompound() {
return compound;
}
public void setBar(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
}
In normal use, this class behaves as you would expect. The methods getCompound
and setCompound
get and set the compound list. However, I'm using this class as an object that's passed in a web service built using JAX-WS. When the JAX-WS compiler sees this class, it ignores the setCompound
and getCompound
accessors, and the only property that appears in the XSD is bar
.
After banging my head against the wall for most of the day, I decided to try changing the name of the private method isCompound
to isACompound
and suddenly everything worked as you'd expect. JAX-WS created the correct schema for the compound
property.
What seems to be happening is that JAX-WS is seeing the isCompound
method (even though it's private) and treating it as a getter with no corresponding setter and therefore ignoring the real public accessors for compound
.
Is there anything in the Java Bean specification that says you can't have a private is<Something>
method where <something>
is also the name of a non-boolean property, which also has its own accessors? Surely anything using reflection on the class should simply ignore private methods?