Re: [Simple-support] Controlling Depth of Serialization
Brought to you by:
niallg
|
From: Karl G. <kar...@gm...> - 2008-07-19 03:53:42
|
Hi Niall,
So I've looked through CycleStrategy and I think I get the general idea of
how it works. Right now I'm focused on just serialization, so I'm working
with setElement and setRoot. But I'm still unclear on how I can achieve
tracking of depth with the information available to me in setElement.
CycleStrategy seems to keep track of the instances it has already seen. If
found, it will only write a reference attribute, otherwise it writes all
attributes of a node. DepthStrategy as I'm calling it would need to keep
track of objects in a similar way, but it would also need to know what
parent element it came from wouldn't it?
Also, in the example you provided I think you may have meant:
public Type getElement(....) {
if(depth++ > 2) {
return new EmptyType();
}
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
>
>
>
>
|