Re: [Simple-support] How to deserialize from a stream
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-09-04 07:31:25
|
Hi,
Yes you can, with a strategy. Currently I do not support top level class="some.class.Name" attributes. The reason is because class= attributes are only written when the expected type is a subclass of the type. I should really add a method such as.
Persister.write(Object value, Class expect, OutputStream out);
Then you could write.
persister.write(value, Object.class, out);
Resulting in a class= attribute at the top leven. However, you can still do this if you like. Create a strategy like so.
public class MyStrategy implements Strategy {
private final Strategy strategy;
public MyStrategy(Strategy strategy){
this.strategy = strategy;
}
public boolean setRoot(Class field, Object value, NodeMap node, Map map){
return strategy.setRoot(Object.class, value, node, map);
}
}
And create it like so:
Strategy main = new DefaultStrategy();
Strategy mine = new MyStrategy(main);
Persister persister = new Persister(mine);
Then you will see top leven class= attributes. Note though you will have to make org.simpleframework.xml.load.DefaultStrategy public. It is currently package protected. I will make it public in the next release as it really is needed to do most non-standard things with simple. Hope this works, if it does not let me know.
A good starting point for learning what the Strategy is, is the javadoc, tutorial, and the unit tests which come with the download.
Regards,
Niall
--- On Wed, 9/3/08, Tony Thompson <Ton...@st...> wrote:
> From: Tony Thompson <Ton...@st...>
> Subject: [Simple-support] How to deserialize from a stream
> To: sim...@li...
> Date: Wednesday, September 3, 2008, 10:35 AM
> I was able to serialize several objects to an output stream
> but now I
> would like to stream them back. There are too many objects
> to load them
> all into memory at once. It looks the Persister.read()
> method will work
> but, I have to pass in the object type that I am reading.
> I don't know
> what the type of the next object is because I have several
> different
> object types written to the XML file. Is there a way to
> stream each
> object back (one object in memory at a time) without
> knowing the object
> type ahead of time?
>
> I was able to serialize/deserialize all of my objects when
> I put them in
> a wrapper object and used @ElementList but, that requires
> they are all
> in memory at the same time so it really doesn't help
> me. Any other
> input would be helpful.
>
> Thanks.
> Tony
>
> This message (and any associated files) is intended only
> for the
> use of the individual or entity to which it is addressed
> and may
> contain information that is confidential, subject to
> copyright or
> constitutes a trade secret. If you are not the intended
> recipient
> you are hereby notified that any dissemination, copying or
> distribution of this message, or files associated with this
> message,
> is strictly prohibited. If you have received this message
> in error,
> please notify us immediately by replying to the message and
> deleting
> it from your computer. Messages sent to and from Stoneware,
> Inc.
> may be monitored.
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move
> Developer's challenge
> Build the coolest Linux based applications with Moblin SDK
> & win great prizes
> Grand prize is a trip for two to an Open Source event
> anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|