Given:
@XmlRootElement(name = "foo")
class Foo {
public Bar getBar() {...}
}
class Bar {
@XmlElement(name = "string")
public String getString() {return "hello";}
}
How do I annotate so the XML will be:
<foo>
<string>hello</string>
</foo>
You probably need to use @XmlSeeAlso annotation on top of your class.
You can use @XmlSeeAlso annotation when you want another Entity bean to be included in the XML output. Can you try this in your Foo class
Update1:
For your comment to remove the bar tag in the XML try using EclipseLink JAXB (MOXy)'s. @XmlPath will solve your issue.
Refer here for more details.
I'm not sure you can to eliminate the tag bar from resulting XML:
http://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXBUsing4.html#wp148576
You could do the following leveraging the
@XmlValue
annotation.Foo
Bar
For More Information