Re: [Simple-support] reference a field of an instance variable
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-02-11 18:36:15
|
Hi,
What you have suggested is static, by this I mean that
it is a static value on an annotation. So why not use
getter and setter methods to serialize your values.
For example instead of annotating the field why not
annotate a method.
public class Class1{
@Element
private Class3 class3;
@Attribute
private long id;
}
public class Class2{
@Attribute(name="class1", references=Class1.id)
private Class1 class1;
@Attribute
public long getId() {
return class1.id;
}
@Attribute
public void setId(long id) {
class1 = new Class1();
class1.id = id;
}
}
This will read and write the elements you want from
Class1.
Niall
--- Quirino Zagarese <qu...@la...> wrote:
> Hi and thank you very much for the fast response!
> The @Replace solution works perfectly; anyway I
> wondered if a construct like
> the one I proposed
> could be useful for serialization purpose only.
> I think so cause you don't need any callbacks and
> each class "decides" how
> to be serialized.
> If you think such a functionality to be interesting,
> I'd like to contribute
> it.
> Thank you again
> Regards
>
> 2008/2/8, Niall Gallagher
> <gal...@ya...>:
> >
> > Hi,
> >
> > Yes you can, but not as an attribute of the
> containing
> > class. All you need to do is use the @Replace
> > annotation on a method. For instance if you wish
> to
> > write a single value you should do the following.
> >
> > private Class1 {
> >
> > @Element(required=false)
> > private Blah other;
> >
> > @Attrobite
> > private int id;
> >
> > @Replace
> > private Class1 replace() {
> > if(isSomeCondition()) {
> > Class1 class1 = new Class1();
> > class1.id = id;
> > return class1;
> > }
> > return this;
> > }
> > }
> >
> > public Class2 {
> >
> > @Element
> > private Class1 value;
> > }
> >
> > This will cause a callback to Class1 before its
> > written to XML.
> >
> > Niall
> >
> >
> > --- Quirino Zagarese <qu...@la...>
> wrote:
> >
> > > Hi,
> > > I've been watching the Simple Framework and I
> found
> > > it very useful and
> > > pretty complete.
> > > I looked at tutorials and javadocs and I
> wondered if
> > > it's possible to
> > > serialize only a single field of a complex
> instance
> > > variable. I'll show it
> > > with an example to make it more clear.
> > >
> > > public class Class1{
> > > @Element
> > > private Class3 class3;
> > >
> > > @Attribute
> > > private long id;
> > >
> > > }
> > >
> > >
> > > public class Class2{
> > > //I want to serialize only the id of
> the
> > > class1 variable, not the
> > > whole state
> > > @Attribute(name="class1"
> > > references=Class1.id)
> > > private Class1 class1;
> > >
> > > }
> > >
> > > I'm using Simple to serialize AJAX responses and
> > > this feature could be very
> > > useful when you want to show a list of
> items(i.e.
> > > products in e-commerce
> > > apps), but you don't want to load all related
> data.
> > > Sorry for my English.
> > > Regards
> > >
> > >
> > >
> > > --
> > > Quirino Zagarese
> > >
> > > LaszloItalia Founder (www.laszloitalia.org)
> > > Software Development Manager - Galilaeus s.r.l.
> > > (www.galilaeus.net)
> > > >
> >
>
-------------------------------------------------------------------------
> > > This SF.net email is sponsored by: Microsoft
> > > Defy all challenges. Microsoft(R) Visual Studio
> > > 2008.
> > >
> >
>
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/>
> > _______________________________________________
> > > Simple-support mailing list
> > > Sim...@li...
> > >
> >
>
https://lists.sourceforge.net/lists/listinfo/simple-support
> > >
> >
> >
> >
> >
> >
>
____________________________________________________________________________________
> > Looking for last minute shopping deals?
> > Find them fast with Yahoo! Search.
> >
>
http://tools.search.yahoo.com/newsearch/category.php?category=shopping
> >
>
>
>
> --
> Quirino Zagarese
>
> LaszloItalia Founder (www.laszloitalia.org)
> Software Development Manager - Galilaeus s.r.l.
> (www.galilaeus.net)
>
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
|