How does JAXB map a class name to an XML element name?

I am using JAXB (version included in JDK 6) to sort objects in XML. The following code snippet gives 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());
    }
}

code> Conclusion from the above
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vipPerson/>

I expect to see the name of the class associated with the element VIPPerson, and not VIPPersonbased on section 8.12.1 in the JAXB specification , which states that

class name: the class name is mapped to the XML name in uppercase using java.beans.Introspector.decapitalize (class name).

The JavaDoc for this method decapitalizesays the following:

, Java. , , () , , , , . , "FooBah" "fooBah", "X" "x", "URL" "URL".

- ?

+3
1

bug . , - , . @XmlRootElement.

+6

Source: https://habr.com/ru/post/1794258/


All Articles