java - How does JAXB map a class name to an XML element name? -
i using jaxb (the version included jdk 6) marshall objects xml. following piece of code yields unexpected results:
public class jaxbtest { @xmlrootelement public static class vipperson {} public static void main(string[] args) throws jaxbexception { stringwriter sw = new stringwriter(); vipperson p = new vipperson(); jaxb.marshal(p, sw); system.out.println(sw.tostring()); } }
output above is <?xml version="1.0" encoding="utf-8" standalone="yes"?> <vipperson/>
i expecting see class name mapped vipperson
element rather vipperson
based on section 8.12.1 in jaxb specification, says
class name: class name mapped xml name de capitalization using java.beans.introspector.decapitalize(class name ).
the javadoc decapitalize
method says this:
utility method take string , convert normal java variable name capitalization. means converting first character upper case lower case, but in (unusual) special case when there more 1 character , both first , second characters upper case, leave alone. "foobah" becomes "foobah" , "x" becomes "x", "url" stays "url".
does implementation violate spec or misunderstanding something?
this caused bug in reference implementation. looks won't fixed due compatibility problems cause. workaround explicitly specify name @xmlrootelement
.
Comments
Post a Comment