Re: [Simple-support] reference a field of an instance variable
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2008-02-08 18:47:09
|
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
|