求助!!!使用JAXB,XML转Java对象,读取连续相同标签时只创建了1个对象且返回最后1个标签内容

返回对象只返回最后一个choice标签内的value

但是Text里放很多还是能够正常读取和转换,只是到了这个连续属性标签就出问题了
求解如何更改,Choc对象只创建了一个,我需要List

Quiz.xml;
想要把choice读取成对象。
前端目前输出,只有最后一个  
quizchoices: Array(1)
	'0': {choices: "Test"}

后端输出
03-24 12:03 [http-nio-8081-exec-1] 
CreateWithoutValue
SetValue null
SetValue True
SetValue False
123
-------------
GetValue Test



<Text>
	<quiz ident="Question_0">
		<quiztype>Choice</quiztype>
		<quizresponse>Single</quizresponse>
		<title>
		Until the 1980s, project management primarily focused on providing schedule and resource data to top management in the military, computer, and construction industries.
		</title>
		<quizchoice>
			<choice ident="I0_C0">True</choice>
			<choice ident="I0_C1">False</choice>
			<choice ident="I0_C2">Test</choice>
		</quizchoice>
	</quiz>
</Text>
QuizListEntity.java  包装类
package com.emperorws.hrmanagement.domain;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.List;


@XmlRootElement(name = "Text")
public class QuizListEntity implements Serializable {

    List<QuizEntity> quizs;

    @XmlElement(name="quiz")
    public List<QuizEntity> getQuizs() {
        return quizs;
    }

    public void setQuizs(List<QuizEntity> quizs) {
        this.quizs = quizs;
    }
}

QuizEntity.java


package com.emperorws.hrmanagement.domain;

import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;


public class QuizEntity implements Serializable {
    private String quizid;
    private String quiztypes;
    private String quizresponses;
    private String quiztitle;
    private List<Choc> quizchoices;

    public QuizEntity(){

    }

    public QuizEntity(String quizid,String quiztype,String quizresponse,String title,List<Choc> quizchoices){
        this.quizid=quizid;
        this.quiztypes=quiztype;
        this.quizresponses=quizresponse;
        this.quiztitle=title;
        this.quizchoices=quizchoices;
    }

    @XmlAttribute(name = "ident")
    public String getQuizid(){
        return quizid;
    }

    public void setQuizid(String quizid){
        this.quizid=quizid;
    }

    @XmlElement(name = "quiztype")
    public String getQuiztypes(){
        return quiztypes;
    }

    public void setQuiztypes(String quiztype){
        this.quiztypes=quiztype;
    }

    @XmlElement(name = "quizresponse")
    public String getQuizresponses(){
        return quizresponses;
    }

    public void setQuizresponses(String quizresponse) {
        this.quizresponses = quizresponse;
    }

    @XmlElement(name = "title")
    public String getTitle(){
        return quiztitle;
    }

    public void setTitle(String title) {
        this.quiztitle = title;
    }


 //ChoiceList
    public List<Choc> getQuizchoices() {
        if (quizchoices==null)
            return null;
        return quizchoices;
    }
    @XmlElement(name = "quizchoice")
    public void setQuizchoices (List<Choc> quizchoice) {
        this.quizchoices = quizchoice;
    }
}

Choc.java (以为命名有影响瞎改的,就是choice)想把变成对象
package com.emperorws.hrmanagement.domain;

import javax.xml.bind.annotation.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@XmlAccessorType(XmlAccessType.NONE)

public class Choc implements Serializable {


    private String choices;

    public Choc(){
		System.out.println("CreateWithoutValue");
    }

    public Choc(String choice){
        System.out.println("CreateWithValue");
        this.choices=choice;
    }
    @XmlElement(name = "choice")
    public String getChoices(){
        System.out.println("GetValue "+choices);
          return choices;
    }
    public void setChoices(String choice) {
        System.out.println("SetValue "+choices);
        this.choices = choice;
    }
}
XML转Java类处理函数,用的JAXB
    public static Object xmlToBean(String xmlPath,Class<?> load) throws JAXBException, IOException{
                JAXBContext context = JAXBContext.newInstance(load);
                Unmarshaller unmarshaller = context.createUnmarshaller();
                Object object = unmarshaller.unmarshal(new File(xmlPath));
                return object;
             }

    public static List<QuizEntity> gg(String args) throws IOException, JAXBException {
                 String xmlPath =  args;
                 Object object = XMLUtil.xmlToBean(xmlPath, QuizListEntity.class);
                 QuizListEntity quizListEntity = (QuizListEntity) object;
                 System.out.println("-------------");
                    // }
                 return quizList;

    }
后端输出
03-24 12:03 [http-nio-8081-exec-1] 
CreateWithoutValue
SetValue null
SetValue True
SetValue False
123
-------------
GetValue Test

你可能感兴趣的:(求助)