After creating the XML using JAXB, not able to get the value of @XmlRootElement in an expected way using @XmlElement or @XmlAttribute.
Code 1
@XmlRootElement(name = "USER_ID")
@XmlAccessorType(XmlAccessType.NONE)
public class UserD {
@XmlElement(name = "USER_ID")
private String userId;
@XmlElement(name = "Name")
private ArrayList<Name> name;
Output
<USER_ID>
<USER_ID>1</USER_ID>
<Name></Name>
<Name></Name>
<Name></Name>
<USER_ID>
Code 2
@XmlRootElement(name = "USER_ID")
@XmlAccessorType(XmlAccessType.NONE)
public class UserD {
@XmlAttribute(name = "USER_ID")
private String userId;
@XmlElement(name = "Name")
private ArrayList<Name> name;
Output 2
<USER_ID USER_ID="1">
<Name></Name>
<Name></Name>
<Name></Name>
<USER_ID>
Required Output
<USER_ID>1
<Name></Name>
<Name></Name>
<Name></Name>
<USER_ID>