为什么我会得到这个结构?我会期望 quiz-->questions--> 和两个问题元素,而不是两个问题元素?
@XmlRootElement
public class Quiz {
private List<Question> questions;
public Quiz() {
questions = new ArrayList<Question>();
}
public List<Question> getQuestions() {
return questions;
}
public void setQuestions(List<Question> questions) {
for (Question question : questions) {
addQuestion(question);
}
}
public void addQuestion(final Question question) {
if (!(questions.contains(question))) {
questions.add(question);
}
}
public void removeQuestion(final Question question) {
if (questions.contains(question)) {
questions.remove(question);
}
}
public int numberOfQuestions() {
return questions.size();
}
}
问题:
@XmlRootElement
public class Question extends AbstractModel {
}
<quiz><questions></questions><questions></questions></quiz>