Hi Bogdan,

It's easy to filter a collection, though you need to write your own 
collection load/store methods to do it. Easiest is to define an Iterator 
for going through the items of the collection, returning only those 
which match your criteria. This means the hasNext() method of the 
Iterator has to check if the current match has been read yet (using 
next()), and if so check to see if there's another match in the 
collection. Then use the <collection> iter-method attribute in the 
binding to specify the method returning the Iterator, and an add-method 
for adding items to the collection (if you're unmarshalling as well as 
marshalling). So basically you're hiding the actual Collection object, 
and instead using the method pair for all access to the collection.

- Dennis

Dennis M. Sosnoski
XML and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117



Bogdan Tanasa wrote:
>
> Hi there,
>
> Is there any way to perform some filtering while marshalling? Say I 
> have a main object, instance of class A with a collection of child 
> objects, instances of B – out of all child objects I would like to 
> serialize only those that match a certain condition.
>
> I know I could
>
> -have B derive from a MyMarshallable class that exposes a property I 
> can set if I want the object to be serialized
>
> -add a get-method in class A and verify the child property – if it 
> indicates serializing should not be performed for the child, return null
>
> But it seems more convenient to me to implement certain methods in the 
> B class itself and also take advantage of a IMarshallingContext 
> argument that would allow me further access to UserContext. That could 
> even be accomplished with a Boolean ‘pre-get’ method – if it returns 
> false skip the marshalling.
>
> Best Regards,
>
> *Bogdan *
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
> trial. Simplify your report design, integration and deployment - and focus on 
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> ------------------------------------------------------------------------
>
> _______________________________________________
> jibx-users mailing list
> jibx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jibx-users
>   

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
jibx-users mailing list
jibx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jibx-users

Reply via email to