Reputation: 315
So what I am looking to do is to achieve this structure:
<root>
<child>value</child>
<child>value</child>
.
.
</root>
The problem is I do not know how many children are there in advances, so need a list. I have tried this but I end up with:
<root>
<child/>
<child/>
.
.
</root>
This is using JAXB.
Please help me out..
Upvotes: 1
Views: 123
Reputation: 315
Okey so What I did was added a new annotation and setter and getter methods and it worked eg:
@XmlValue protected String myval;
public String getMyval(){
return this.myval;
}
public void setMyval(String myval){
this.myval = myval;
}
Upvotes: 0
Reputation: 149007
You could do one the following:
Option #1
Root
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {
List<String> child;
}
Option #2
Root
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {
List<Child> child;
}
Child
@XmlAccessorType(XmlAccessType.FIELD)
public class Child {
@XmlValue
String value;
}
For More Information
Upvotes: 2