Re: [Simple-support] How to deserialize from a stream
Brought to you by:
niallg
|
From: <Nia...@ub...> - 2008-09-09 10:58:59
|
Hi,
Sorry, thought I had responded. Just do this.
Object o = persister.read(Object.class, inputSource);
Every object subclasses the object class, so the type in the XML will
match. It does not need to ignore.
Hope this helps,
Niall
-----Original Message-----
From: sim...@li...
[mailto:sim...@li...] On Behalf Of Tony
Thompson
Sent: 09 September 2008 11:52
To: gal...@ya...; sim...@li...
Subject: Re: [Simple-support] How to deserialize from a stream
Any input on this issue?
So, if I create the Strategy to write, how do I read the objects back,
persister.read( ????, input )? If the class= attribute is in the XML,
does the read() method ignore the type parameter? I am still confused
about that part, sorry.
Thanks for the detailed response.
Tony
-----Original Message-----
From: Niall Gallagher [mailto:gal...@ya...]
Sent: Thursday, September 04, 2008 3:31 AM
To: sim...@li...; Tony Thompson
Subject: Re: [Simple-support] How to deserialize from a stream
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
------------------------------------------------------------------------
-
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
Visit our website at http://www.ubs.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mails are not encrypted and cannot be guaranteed to be secure or
error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The sender
therefore does not accept liability for any errors or omissions in the
contents of this message which arise as a result of e-mail transmission.
If verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities
or related financial instruments.
UBS Limited is a company registered in England & Wales under company
number 2035362, whose registered office is at 1 Finsbury Avenue,
London, EC2M 2PP, United Kingdom.
UBS AG (London Branch) is registered as a branch of a foreign company
under number BR004507, whose registered office is at
1 Finsbury Avenue, London, EC2M 2PP, United Kingdom.
UBS Clearing and Execution Services Limited is a company registered
in England & Wales under company number 03123037, whose registered
office is at 1 Finsbury Avenue, London, EC2M 2PP, United Kingdom.
|