Search code examples
javaandroidxmlxstream

xStream deserialization in java


<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>

I am having a horrible time of figuring out how xstream wants me to set this up.... this is what I am currently doing:

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;
    }
}

Coud someone please help me figure out how to set up the structure so that xstream will fill it in from the bove xml?


Solution

  • I think you need the structure of getter and setter in your static class just as public static class Employee, for "int id" and "String content".