Re: [morph-user] How do I convert a Collection of objects?
Brought to you by:
orangeherbert,
sgarlatm
|
From: Matt S. <sga...@us...> - 2005-03-03 17:50:01
|
Hello again Hernan, I just took a look at the code that's in Morph 0.8.2, and the ContainerCopier should detect you are converting to a ChildDTO[] array and automatically do the conversion from a List or array of ChildDO objects. It will delegate to the converter you specify as the nestedTransformer (that is a protected property of the underlying BaseTransformer that is made public in the ContainerCopier). In Morph 0.8.3, which I will release this weekend, that property has been renamed graphTransformer. Also, in Morph 0.8.3 if you want to use an untyped collection, you can force a transformation to nested ChildDTO objects in your collection by populating the containedSourceToDestinationMapping property of the CollectionCopier. As I mentioned in a previous post, I'll release Morph 0.8.3 this weekend :) Matt Hernan Silberman wrote: >On Wed, 2 Mar 2005, Matt Sgarlata wrote: > > > >>Hi Hernan, I'm glad you've found the package useful! >> >> > >Sure, thanks for the quick response! > > > >>If your destination ParentDTO exposes its children property as a >>ChildDTO[] array, I think Morph should detect that a conversion is >>necessary. If you want to do the conversion to an untyped collection >>(e.g. - a List of ChildDTO), then you'll have to wait until the next >>release :) I've actually already written the code that does this, I >>just haven't polished it into a release yet. Can you use an array, or >>would you like me to do another release for you? >> >> > >I can use an array, but do I need to write a new Converter to go from ChildDO[] >to ChildDTO[], or can I leverage the Converter I already have for going from >ChildDO to ChildDTO? > >Ultimately, I do want to be able to transform any graph to any other graph >including the untyped collections. The source graph in my case is a Domain >Object Model which is persisted using Hibernate... so it heavily uses java.util >Collections to define relations. > > > >>This past couple weeks I finally had a chance to use Morph with one of >>my own projects (we have an object graph generated by Hibernate that >>needs to be serialized and sent to a remote client using Hessian). To >>accomplish this, I made all the necessary changes to allow cyclic graphs >>to be converted and to allow for more advanced collection >>transformations like the type you mention, Hernan. I was aiming to do a >>release this weekend, but if anyone needs it sooner, I can certainly do >>my best to do a new release tomorrow. >> >> > >I don't want to hurry you like that, I'm still only beginning to use the >framework so there's no rush. > >thanks again... >Hernan > > > > >>Hernan Silberman wrote: >> >> >> >>>Firstly, thanks for building Morph, I can tell it's going to save me tons of >>>time and many other people too. >>> >>>I'm just starting out with Morph and I have a simple question. I have a >>>DelegatingTransformer configured in my code that knows all about the custom >>>transformers I've built. >>> >>>Now I'm building a new Transformer for a class ParentDO that has a collection of >>>ChildDO instances and a simple accessor method: >>> >>>public Collection getChildren(); >>> >>>How do I tell Morph to convert all of the ChildDO objects in >>>someParent.getChildren() to some other type (ChildDTO)? >>> >>>Being overly simplistic about things, I'm looking for a method like this: >>>Collection Morph.convert( DestinationDTO.class, Collection ); >>> >>>Any help is much appreciated. >>> >>>thanks... >>>hernan >>> >>> > > > >------------------------------------------------------- >SF email is sponsored by - The IT Product Guide >Read honest & candid reviews on hundreds of IT Products from real users. >Discover which products truly live up to the hype. Start reading now. >http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click >_______________________________________________ >morph-user mailing list >mor...@li... >https://lists.sourceforge.net/lists/listinfo/morph-user > > > |