Riccardo Cipolleschi
Riccardo Cipolleschi

Reputation: 235

Jaxb Unmarshall finds an expected tag and fails because it's unexpected

i'm trying to unmarshall the following lines of xml:

<?xml version="1.0" encoding="utf-8"?>
<StazioneStatusBikeMi xmlns="http://atm.it/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 

   <IdStazione>1</IdStazione>
   <OraAggiornamento>2013-04-04T14:49:03</OraAggiornamento>
   <BiciDisponibili>20</BiciDisponibili>
   <BiciRotte>0</BiciRotte>
   <StalliVuoti>4</StalliVuoti>
   <StalliRotti>0</StalliRotti>
   <StalliTotale>24</StalliTotale>
</StazioneStatusBikeMi>

I have to use JAXB to unmarshall it.

The problem is that the unmarshall method throws the following exception:

unexpected element (uri:"http://atm.it/", local:"StazioneStatusBikeMi"). Expected elements are <{http://atm.it}StazioneStatusBikeMi>

It appears perfect to me... Where am i wrong?

I copy the class I'm using to unmarshall:

@XmlRootElement(name = "StazioneStatusBikeMi", namespace="http://atm.it")
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
public class StazioneStatusBikeMi extends BaseDTO {

    private int idStazione;
    private Timestamp oraAggiornamento;
    private int biciDisponibili;
    private int biciRotte;
    private int stalliVuoti;
    private int stalliRotti;
    private int stalliTotale;

    public StazioneStatusBikeMi() {
        super();
    }

    public StazioneStatusBikeMi(int idStazione, Timestamp oraAggiornamento,
        int biciDisponibili, int biciRotte, int stalliVuoti,
        int stalliRotti, int stalliTotale) {
        super();
        this.idStazione = idStazione;
        this.oraAggiornamento = oraAggiornamento;
        this.biciDisponibili = biciDisponibili;
        this.biciRotte = biciRotte;
        this.stalliVuoti = stalliVuoti;
        this.stalliRotti = stalliRotti;
        this.stalliTotale = stalliTotale;
    }

    @XmlElement(name = "IdStazione")
    public int getIdStazione() {
        return idStazione;
    }


    public void setIdStazione(int idStazione) {
        this.idStazione = idStazione;
    }

    @XmlElement(name = "OraAggiornamento")
    public Timestamp getOraAggiornamento() {
        return oraAggiornamento;
    }

    public void setOraAggiornamento(Timestamp oraAggiornamento) {
        this.oraAggiornamento = oraAggiornamento;
    }

    @XmlElement(name = "BiciDisponibili")
    public int getBiciDisponibili() {
        return biciDisponibili;
    }

    public void setBiciDisponibili(int biciDisponibili) {
        this.biciDisponibili = biciDisponibili;
    }

    @XmlElement(name = "BiciRotte")
    public int getBiciRotte() {
        return biciRotte;
    }

    public void setBiciRotte(int biciRotte) {
        this.biciRotte = biciRotte;
    }

@XmlElement(name = "StalliVuoti")
    public int getStalliVuoti() {
        return stalliVuoti;
    }

    public void setStalliVuoti(int stalliVuoti) {
        this.stalliVuoti = stalliVuoti;
    }

    @XmlElement(name = "StalliRotti")
    public int getStalliRotti() {
        return stalliRotti;
    }

    public void setStalliRotti(int stalliRotti) {
        this.stalliRotti = stalliRotti;
    }

    @XmlElement(name = "StalliTotale")
    public int getStalliTotale() {
        return stalliTotale;
    }

    public void setStalliTotale(int stalliTotale) {
        this.stalliTotale = stalliTotale;
    }   
}

Thank you for your help! Rik

Upvotes: 2

Views: 53

Answers (1)

lexicore
lexicore

Reputation: 43689

Mind the trailing slash:

<StazioneStatusBikeMi xmlns="http://atm.it/" ...
                                     here ^

Should be http://atm.it.

A your error message clearly suggests:

Expected elements are <{http://atm.it}StazioneStatusBikeMi>
                                     ^

Upvotes: 3

Related Questions