package u2Home.task1;

public class Train {
}

package u2Home.task1;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "train")
// определяем последовательность тегов в XML

@XmlType(propOrder = {"from", "to", "date", "departure"})
public class Train {
    private int id;
    private String from;
    private String to;
    private String date;
    private String departure;

    public Train(){
    }

    public Train(int id, String from, String to, String date, String departure) {
        this.id = id;
        this.from = from;
        this.to = to;
        this.date = date;
        this.departure = departure;
    }


    public int getId() {
        return id;
    }
    @XmlAttribute
    public void setId(int id) {
        this.id = id;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getTo() {
        return to;
    }

    public void setTo(String to) {
        this.to = to;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getDeparture() {
        return departure;
    }

    public void setDeparture(String departure) {
        this.departure = departure;
    }

//    @Override
//    public String toString() {
//        return "train{" +
//                "id=" + id +
//                ", from='" + from + '\'' +
//                ", to=" + to +
//                ", date='" + date + '\'' +
//                ", departure='" + departure + '\'' +
//                '}';
//    }
}

add code