java - why does XMLEncoder miss a property? -


i have java class

class go {    public boolean issha1() {     return true;   }   public string getsha1() {     return this.sha1;   }   public string setsha1(string sha1) {   }   ... } 

when attempt encode using java's java.beans.xmlencoder, outputs properties except sha1. it's it's skipping property!

you aren't following javabeans specification, don't expect handle arbitrary naming.

javabeans says if finds pair of accessors, void setx(y) , y getx(), x identified read-write property of type y. it's specific type, y, being same in both cases. (the notation mine, i'm trying illustrate in concrete manner.) if getx() method missing, x write-only property. if setx(y) missing, x read-only property.

properties type boolean have special treatment. if there's method boolean isx(), used read access property. it's okay if there's boolean getx() method too, won't utilized.

in code, setsha1() ignored default introspection, because it's called set takes no argument.

however, have given issha1() , getsha1() different return types, introspector can't tell type of sha1 property should be. behavior here not defined specification. fix providing explicit bean descriptors, no 1 this.

so, upshot is, don't this. follow conventions given in specification.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -