JAXB Java generating XML, Why lowercase?

前端 未结 4 490
天命终不由人
天命终不由人 2020-12-11 00:49

When I run this code:

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.b         


        
4条回答
  •  無奈伤痛
    2020-12-11 01:54

    The behaviour you are seeing is the result of the standard JAXB (JSR-222) XML name to Java name conversion algorithm.

    You can use the @XmlRootElement annotation to specify a name:

    @XmlRootElement(name="Employee")
    @XmlAccessorType(XmlAccessType.FIELD)
    class Employee {
        ...
    }
    

    I'm the EclipseLink JAXB (MOXy) lead, and we have an extension that allows you to override the default name conversion algorithm that you may be interested in:

    • http://blog.bdoughan.com/2011/05/overriding-jaxbs-name-mangling.html

提交回复
热议问题