Re: [Simple-support] Controlling Depth of Serialization
Brought to you by:
niallg
|
From: Karl G. <kar...@gm...> - 2008-07-17 19:13:09
|
Hi Niall, Thanks for the reply. I had a feeling CycleStrategy might be
applicable here, but I'm afraid I'm not clear on how to implement the
proposed approach. I will need to dig deeper into the examples to get a feel
for it now that I know this is a potential solution.
This may be somewhat out of the ordinary, but B does need to serialize C if
the serialization process begins with B as the root. So, the annotations do
need to be in the class definitions. My temporary solution was to use a lazy
initialization of C from B, but I feel that having the serializer limit
traversal of the graph is still the best option.
On Thu, Jul 17, 2008 at 5:05 AM, Niall Gallagher <gal...@ya...>
wrote:
> Hi,
>
> If you don't annotate the reference to C then it wont be serialized. There
> is another way also. If you implement a Strategy you can return a Type such
> that the Type.isReference == true then it wont serialize it. For instance in
> your strategy implementation if you return the following.
>
> public Type setElement(....) {
> if(depth++ > 2) {
> return new EmptyType();
> }
> }
>
> To see exactly what is involved in this look at the cycle strategy.
> However, I think what you are looking for is a reference to C in B that is
> not annotated. For example
>
>
> @Root
> public class A {
> @Element
> private B b;
> }
>
> @Root
> public class B {
> private C c;
> }
>
> public class C {
> }
>
> Here if you serialize A, only reference to b will be serialized. B's
> reference to C will not be serialized as it is not annotated.
>
> Niall
>
> --- On Wed, 7/16/08, Karl Garske <kar...@gm...> wrote:
>
> > From: Karl Garske <kar...@gm...>
> > Subject: [Simple-support] Controlling Depth of Serialization
> > To: sim...@li...
> > Date: Wednesday, July 16, 2008, 2:54 PM
> > Hello, Is there any way to control the depth of
> > serialization through
> > something like the Persister? For example, my object graph
> > might look
> > something like A->B->C where A,B,C are objects and
> > -> is the direction of
> > reference. Is there a way to specify depth=2 and have it
> > only serialize A
> > and B, but not C? My apologies if this is documented
> > somewhere, but I didn't
> > see it in the tutorial.
> >
> >
> Thanks!-------------------------------------------------------------------------
> > 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
>
>
>
>
|