0
<requests>    
    <request id="246">
        <employee id="40350">Michael Daniels</employee>
        <start>2012-10-20</start>
        <end>2012-10-25</end>
        <created>2012-10-11</created>
        <status lastChanged="2012-10-24" lastChangedByUserId="2270">superceded</status>
        <type id="4">Vacation</type>
        <amount unit="hours">2</amount>
        <notes>
            <note from="employee">Having wisdom teeth removed.</note>
            <note from="manager">Get well soon</note>
        </notes>
    </request>
    <request id="248">
        <employee id="40350">Michael Daniels</employee>
        <start>2012-11-12</start>
        <end>2012-11-15</end>
        <created>2012-10-19</created>
        <status lastChanged="2012-10-30" lastChangedByUserId="2270">superceded</status>
        <type id="4">Vacation</type>
        <amount unit="hours">2</amount>
        <notes>
            <note from="employee">My dog ate my homework so I can't come to work.</note>
        </notes>
    </request>

我很难弄清楚 xstream 想要我如何设置它......这就是我目前正在做的事情:

class Holder
{
    Requests requests;

    @XStreamAlias("requests")
    public static class Requests
    {
        List<Request> requests = new ArrayList<Request>();
    }

    @XStreamAlias("request")
    public static class Request
    {
        int id;
        Employee employee;
        String start;
        String end;
        String created;
        Status status;
        Type type;
        Amount amount;
        Notes notes;

    }

    public static class Employee
    {
        int id;
        String content;
    }
    public static class Status
    {
        String content;
        String lastChanged;
        int lastChangedByUserId;
    }
    public static class Type
    {
        int id;
        String content;
    }
    public static class Amount
    {
        String unit;
        int content;
    }
    public static class Notes
    {
        List<Note> notes = new ArrayList<Note>();
    }
    public static class Note
    {
        String from;
        String content;
    }
}

有人请帮我弄清楚如何设置结构,以便xstream从bove xml填充它?

4

1 回答 1

0

我认为您需要静态类中的 getter 和 setter 结构,就像public static class Employee“int id”和“String content”一样。

于 2012-11-08T01:43:51.847 回答