Domanda

I have an XML stream containing date and time in two different elements. I'm deserializing this to a "Match" object containing two String fields:

@Element
public String MatchDate;

@Element
public String MatchStartTime;

This works fine but I would like to merge these two values into a Calendar object as I later in the code have to subtract some seconds from the date. So I have an additional field in my class:

public Calendar MatchCal;

with no annotation as it's not part of the XML.

I could easily go through all elements in my list after the initial serialization and if the performance overhead using this approach is to be disregarded maybe that's the way to go.

But... is it possible to have my MatchCal object populated "on the fly" during the deserialization.

And if so how?

È stato utile?

Soluzione

Per the tutorial:

http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#callback

I think the @Commit annotation would work for you. This will allow you to execute logic right before the deserialization process completes.

e.g.)

@Commit
public void setCalendar() {
    matchCal = new GregorianCalendar();
    // parse and set time, etc
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top