Is there any way to do mapping with single java bean for such simple xml:
<item lang="en">
<item-url>some url</item-url>
<parent id="id_123"/>
</item>
I've tried something like this:
@XmlRootElement( name = "item" )
public class Item {
@XmlElement( name = "item-url" )
private String url;
@XmlAttribute( name = "parent/@id" )
// Of course XPath doesn't work here, but it would be great...
private String parentId;
}
In other words - how can I access attribute of internal element without creating of corresponding bean?
As I didn't want to create redundant classes in my package, the best solution I've found is:
You could use an
XmlAdapter
:ParentIdAdapter
Item
If you are using EclipseLink MOXy as your JAXB provider then you could leverage the
@XmlPath
extension to do the following: