Reputation: 86925
@XmlRootElement
public class MyRoot {
private List<SubRootDTO> subs;
}
public class SubRootDTO {
}
How can I give an explicit JAXB name to the SubRootDTO
class?
Upvotes: 1
Views: 70
Reputation: 4940
@XmlRootElement
class MyRoot {
private List<SubRootDTO> subs;
...
@XmlElementRef(name = "CustomName")
public List<SubRootDTO> getSubs(){
return subs;
}
}
class SubRootDTO {
}
In contrast to annotate SubRootDTO
with @XmlRootElement(name = "XYZ")
, @XmlElementRef(name = "ABC")
allows you to name the element differently for each reference.
Upvotes: 0
Reputation: 149047
There are a couple of different options:
SubRootDto
with @XmlRootElement
and then use @XmlElementRef
on all mapped fields/properties that reference it.SubRootDto
properties with @XmlElement
.Upvotes: 1