reflection - Java private method hiding public accessors -


i have class 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 know      // if compound instance     private boolean iscompound() {        return compound != null && compound.size() != 0;     }      // public setter compound instance var     public void setcompound(list<foo> compound) {         this.compound = compound;     }      // public getter 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, class behaves expect. methods getcompound , setcompound , set compound list. however, i'm using class object that's passed in web service built using jax-ws. when jax-ws compiler sees class, ignores setcompound , getcompound accessors, , property appears in xsd bar.

after banging head against wall of day, decided try changing name of private method iscompound isacompound , worked you'd expect. jax-ws created correct schema compound property.

what seems happening jax-ws seeing iscompound method (even though it's private) , treating getter no corresponding setter , therefore ignoring real public accessors compound.

is there in java bean specification says can't have private is<something> method <something> name of non-boolean property, has own accessors? surely using reflection on class should ignore private methods?

what happens if change:

 return compound != null && compound.size() != 0;  //to:  private boolean iscompound() {  boolean check = false;  if(compound !=null && compound.size()!=0){     check  = true;  }else{     check  =false;  }     return check;  }  //or @xmlaccessortype(xmlaccesstype.none) on class , @xmlelement , @xmlattribute on get/set methods. 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -