How to put a class attribute into a field with xstream

301 views Asked by At

I want to change from this output

<Event>
    <eventState class="scientificEvents.state.EventRegistered">
        <event reference="../.."/>
    </eventState>
</Event>

to this output

<Event>
    <eventState>scientificEvents.state.EventRegistered</eventState>
</Event>

Have been looking everywhere for this and can't find anything! Only adding fields as attributes which is not what I'm looking for

Here are my classes

public class Event{
    private EventState eventState;
}

EventState

public interface EventState{}

Class that implements EventState

public abstract class EventStateImpl implements EventState
{
   private Event event;

   public EventStateImpl(Event e)
       {
        event = e;
       }
 }

Set this classe as a state of the event

public class EventRegistered extends EventStateImpl
{
    public EventRegistered(Event e)
    {
        super(e);
    }
}

Basically the event holds a class in its attribute and I want to put it as a field in xml output. This is what I'm doing at the moment

File file = new File("events.xml");
XStream xstream = new XStream(new DomDriver());
Event event=new Event();
event.setState(new EventRegistered());
FileWriter out = new FileWriter(file)
String xml = xstream.toXML(events);
out.write(xml);
out.close();

Thanks in advance

0

There are 0 answers