【问题标题】:xStream deserialization in javajava中的xStream反序列化
【发布时间】:2012-11-08 01:28:38
【问题描述】:
<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 中填充它?

【问题讨论】:

    标签: java android xml xstream


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-29
      相关资源
      最近更新 更多