3
votes

I have updated the jaxb library to version 2.0. I am using the following jars, jaxb-api-2.0.jar and jaxb-imp-2.0.jar. Now the problem is, it's not using the @XmlRootElement(name="something"). But with the help of previous library, the xml used the defined name "something" in the generated xml. Right now it's taking the class name in camel case instead of "something" defined in the name attribute. Is it a bug of latest jaxb library? Please help!

2

2 Answers

1
votes

Below is an example that may help. The @XmlRootElement annotation will control the name of the root element for the XML document. If you want to control the name of an inner element you can use the @XmlElement annotation.

SomeObject

package forum9272675;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="something")
public class SomeObject {

    private SomethingElse somethingElse;

    @XmlElement(name="something-else")
    public SomethingElse getSomethingElse() {
        return somethingElse;
    }

    public void setSomethingElse(SomethingElse somethingElse) {
        this.somethingElse = somethingElse;
    }

}

SomethingElse

package forum9272675;

public class SomethingElse {

}

Output

<?xml version="1.0" encoding="UTF-8"?>
<something>
    <something-else/>
</something>
0
votes

In my child class I was using the @XmlRootElement(name="some-thing"). In addition to it, when I use @XmlType(name="some-thing") my problem got resolved!