Unmarshalling jaxB doesn't work, objects null

青春壹個敷衍的年華 提交于 2019-12-13 01:34:26

问题


I have a problem with jaxB. There is no exception and here is my xml ;

<event>
 <event_datetimeGMT>2015-02-27 17:00</event_datetimeGMT>
 <gamenumber>443364144</gamenumber>
 <sporttype>Basketball</sporttype>
 <league>Adriatic</league>
 <IsLive>No</IsLive>
 <participants>
  <participant>
   <participant_name>Cedevita</participant_name>
   <contestantnum>1001</contestantnum>
   <rotnum>1001</rotnum>
   <visiting_home_draw>Home</visiting_home_draw>
  </participant>
 <participant>
  <participant_name>Mega Leks</participant_name>
  <contestantnum>1002</contestantnum>
  <rotnum>1002</rotnum>
  <visiting_home_draw>Visiting</visiting_home_draw>
 </participant>
</participants>
<periods>
 <period>
  <period_number>0</period_number>
  <period_description>Game</period_description>
  <periodcutoff_datetimeGMT>2015-02-27 17:00</periodcutoff_datetimeGMT>
  <period_status>I</period_status>
  <period_update>open</period_update>
  <spread_maximum>500</spread_maximum>
  <moneyline_maximum>500</moneyline_maximum>
  <total_maximum>500</total_maximum>
  <moneyline>
   <moneyline_visiting>583</moneyline_visiting>
   <moneyline_home>-720</moneyline_home>
  </moneyline>
  <spread>
   <spread_visiting>12</spread_visiting>
   <spread_adjust_visiting>-104</spread_adjust_visiting>
   <spread_home>-12</spread_home>
   <spread_adjust_home>-106</spread_adjust_home>
  </spread>
  <total>
   <total_points>164</total_points>
   <over_adjust>-101</over_adjust>
   <under_adjust>-109</under_adjust>
  </total>
 </period>
</periods>

here is main class ;

@XmlRootElement (name = "pinnacle_line_feed")
    public class PinnacleLineFeed {

    private Long PinnacleFeedTime;
    private Long lastContest;
    private Long lastGame;
    private List<Event> events;

    @XmlAttribute(name = "PinnacleFeedTime")
    public Long getPinnacleFeedTime() {
        return PinnacleFeedTime;
    }

    public void setPinnacleFeedTime(Long pinnacleFeedTime) {
        PinnacleFeedTime = pinnacleFeedTime;
    }

    @XmlAttribute (name = "lastContest")
    public Long getLastContest() {
        return lastContest;
    }

    public void setLastContest(Long lastContest) {
        this.lastContest = lastContest;
    }

    @XmlAttribute (name = "lastGame")
    public Long getLastGame() {
        return lastGame;
    }

    public void setLastGame(Long lastGame) {
        this.lastGame = lastGame;
    }

    @XmlElement (name = "events")
    public List<Event> getEvents() {
        return events;
    }

    public void setEvents(List<Event> events) {
        this.events = events;
    }
}

you can see full xml from the url which i shared at my first post

and here is my pojos ;

public class Event {

private String event_datetimeGMT;
private Long gamenumber;
private String sporttype;
private String league;
private String IsLive;
private List<Participant> participants;
private List<Period> periods;

@XmlAttribute (name = "event_datetimeGMT")
public String getEvent_datetimeGMT() {
    return event_datetimeGMT;
}

public void setEvent_datetimeGMT(String event_datetimeGMT) {
    this.event_datetimeGMT = event_datetimeGMT;
}

@XmlAttribute (name = "gamenumber")
public Long getGamenumber() {
    return gamenumber;
}

public void setGamenumber(Long gamenumber) {
    this.gamenumber = gamenumber;
}

@XmlAttribute (name = "sporttype")
public String getSporttype() {
    return sporttype;
}

public void setSporttype(String sporttype) {
    this.sporttype = sporttype;
}

@XmlAttribute (name = "league")
public String getLeague() {
    return league;
}

public void setLeague(String league) {
    this.league = league;
}

@XmlAttribute (name = "IsLive")
public String getIsLive() {
    return IsLive;
}

public void setIsLive(String isLive) {
    this.IsLive = isLive;
}

@XmlElement(name = "participant")
public List<Participant> getParticipants() {
    return participants;
}

public void setParticipants(List<Participant> participants) {
    this.participants = participants;
}

@XmlElement(name = "period")
public List<Period> getPeriods() {
    return periods;
}

public void setPeriods(List<Period> periods) {
    this.periods = periods;
}

}

public class Participants {

    private List<Participant> participants;

    @XmlElement(name = "participant")
    public List<Participant> getParticipants() {
        return participants;
    }

    public void setParticipants(List<Participant> participants) {
        this.participants = participants;
    }
}

public class Participant {

    private String participant_name;
    private Long contestantnum;
    private Long rotnum;
    private String visiting_home_draw;

    @XmlAttribute(name = "participant_name")
    public String getParticipant_name() {
        return participant_name;
    }

    public void setParticipant_name(String participant_name) {
        this.participant_name = participant_name;
    }

    @XmlAttribute (name = "contestantnum")
    public Long getContestantnum() {
        return contestantnum;
    }

    public void setContestantnum(Long contestantnum) {
        this.contestantnum = contestantnum;
    }

    @XmlAttribute (name = "rotnum")
    public Long getRotnum() {
        return rotnum;
    }

    public void setRotnum(Long rotnum) {
        this.rotnum = rotnum;
    }

    @XmlAttribute (name = "visiting_home_draw")
    public String getVisiting_home_draw() {
        return visiting_home_draw;
    }

    public void setVisiting_home_draw(String visiting_home_draw) {
        this.visiting_home_draw = visiting_home_draw;
    }
}

public class Periods {
    private List<Period> periods;

    @XmlElement(name = "period")
    public List<Period> getPeriods() {
        return periods;
    }

    public void setPeriods(List<Period> periods) {
        this.periods = periods;
    }
}

public class Period {

    private int period_number;
    private String period_description;
    private String periodcutoff_datetimeGMT;
    private String period_status;
    private String period_update;
    private int spread_maximum;
    private int moneyline_maximum;
    private int total_maximum;
    private Moneyline moneyline;
    private Spread spread;
    private Total total;

    @XmlAttribute(name = "period_number")
    public int getPeriod_number() {
        return period_number;
    }

    public void setPeriod_number(int period_number) {
        this.period_number = period_number;
    }

    @XmlAttribute(name = "period_description")
    public String getPeriod_description() {
        return period_description;
    }

    public void setPeriod_description(String period_description) {
        this.period_description = period_description;
    }

    @XmlAttribute(name = "periodcutoff_datetimeGMT")
    public String getPeriodcutoff_datetimeGMT() {
        return periodcutoff_datetimeGMT;
    }

    public void setPeriodcutoff_datetimeGMT(String periodcutoff_datetimeGMT) {
        this.periodcutoff_datetimeGMT = periodcutoff_datetimeGMT;
    }

    @XmlAttribute(name = "period_status")
    public String getPeriod_status() {
        return period_status;
    }

    public void setPeriod_status(String period_status) {
        this.period_status = period_status;
    }

    @XmlAttribute(name = "period_update")
    public String getPeriod_update() {
        return period_update;
    }

    public void setPeriod_update(String period_update) {
        this.period_update = period_update;
    }

    @XmlAttribute(name = "spread_maximum")
    public int getSpread_maximum() {
        return spread_maximum;
    }

    public void setSpread_maximum(int spread_maximum) {
        this.spread_maximum = spread_maximum;
    }

    @XmlAttribute(name = "moneyline_maximum")
    public int getMoneyline_maximum() {
        return moneyline_maximum;
    }

    public void setMoneyline_maximum(int moneyline_maximum) {
        this.moneyline_maximum = moneyline_maximum;
    }

    @XmlAttribute(name = "total_maximum")
    public int getTotal_maximum() {
        return total_maximum;
    }

    public void setTotal_maximum(int total_maximum) {
        this.total_maximum = total_maximum;
    }

    @XmlElement (name = "moneyline")
    public Moneyline getMoneyline() {
        return moneyline;
    }

    public void setMoneyline(Moneyline moneyline) {
        this.moneyline = moneyline;
    }

    @XmlElement (name = "spread")
    public Spread getSpread() {
        return spread;
    }

    public void setSpread(Spread spread) {
        this.spread = spread;
    }

    @XmlElement (name = "total")
    public Total getTotal() {
        return total;
    }

    public void setTotal(Total total) {
        this.total = total;
    }
}

public class Moneyline {

    private int moneyline_visiting;
    private int moneyline_home;

    @XmlAttribute(name = "moneyline_visiting")
    public int getMoneyline_visiting() {
        return moneyline_visiting;
    }

    public void setMoneyline_visiting(int moneyline_visiting) {
        this.moneyline_visiting = moneyline_visiting;
    }

    @XmlAttribute(name = "moneyline_home")
    public int getMoneyline_home() {
        return moneyline_home;
    }

    public void setMoneyline_home(int moneyline_home) {
        this.moneyline_home = moneyline_home;
    }
}

public class Spread {
    private int spread_visiting;
    private int spread_adjust_visiting;
    private int spread_home;
    private int spread_adjust_home;

    @XmlAttribute(name = "spread_visiting")
    public int getSpread_visiting() {
        return spread_visiting;
    }

    public void setSpread_visiting(int spread_visiting) {
        this.spread_visiting = spread_visiting;
    }

    @XmlAttribute(name = "spread_adjust_visiting")
    public int getSpread_adjust_visiting() {
        return spread_adjust_visiting;
    }

    public void setSpread_adjust_visiting(int spread_adjust_visiting) {
        this.spread_adjust_visiting = spread_adjust_visiting;
    }

    @XmlAttribute(name = "spread_home")
    public int getSpread_home() {
        return spread_home;
    }

    public void setSpread_home(int spread_home) {
        this.spread_home = spread_home;
    }

    @XmlAttribute(name = "spread_adjust_home")
    public int getSpread_adjust_home() {
        return spread_adjust_home;
    }

    public void setSpread_adjust_home(int spread_adjust_home) {
        this.spread_adjust_home = spread_adjust_home;
    }
}

public class Total {
    private int total_points;
    private int over_adjust;
    private int under_adjust;

    @XmlAttribute(name = "total_points")
    public int getTotal_points() {
        return total_points;
    }

    public void setTotal_points(int total_points) {
        this.total_points = total_points;
    }

    @XmlAttribute(name = "over_adjust")
    public int getOver_adjust() {
        return over_adjust;
    }

    public void setOver_adjust(int over_adjust) {
        this.over_adjust = over_adjust;
    }

    @XmlAttribute(name = "under_adjust")
    public int getUnder_adjust() {
        return under_adjust;
    }

    public void setUnder_adjust(int under_adjust) {
        this.under_adjust = under_adjust;
    }
}

and my test method ;

private static void unmarshall() {

    try {
        JAXBContext jc = JAXBContext.newInstance(PinnacleLineFeed.class);
        URL url = new URL("http://xml.pinnaclesports.com/pinnacleFeed.aspx?");

        Unmarshaller unmarshaller = jc.createUnmarshaller();

        PinnacleLineFeed pinnacleLineFeed = (PinnacleLineFeed) unmarshaller.unmarshal(url);

        System.out.println("bakıcez");


    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

When i try to unmarshall this xml, all fields are null. And there is no exception. Can anyone help ?

来源:https://stackoverflow.com/questions/28771769/unmarshalling-jaxb-doesnt-work-objects-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!