Re: [morph-developer] Copying Objects to Maps
Brought to you by:
orangeherbert,
sgarlatm
|
From: Matt B. <gud...@ya...> - 2007-02-26 21:57:22
|
Hmph--hadn't noticed the Spring file. :) This is something I would like to think more about for the long-term. I've been looking at this stuff for several hours today (and once more revisited the UNfruitful path of having SDT flat-out implement NodeCopier, though I almost got there) and now I think a tiny piece of effort that would have quite a bit of yield would simply be a boolean appendDefaultComponents flag for SDT. This would greatly simplify Spring (or otherwise) configuration of an application's top-level SDT where the developer provides custom transformer implementations, but wants to defer to Morph's default behavior for standard cases. Hopefully this would cover >= 90% of what developers would want to do, while still leaving the door open for more complex configurations. "Make easy things easy and hard things possible." -Matt (B) --- Matt Sgarlata <Mat...@wh...> wrote: > Matt Benson wrote: > > Follow Up: > > > > 1) No news is good news, so I will implement such > that > > beans will indeed map properties to map entries by > > default. > > > OK, I had a chance to look over this. The reason > for the old behavior > was an implementation coincidence and not really > intended. It happened > because: > - MapReflector is perfectly happy treating a Map as > both a container and > as a bean > - ContainerCopier has to come before > PropertyNameMatchingCopier, > otherwise when collections were encountered you > would have the > properties of the collection copied rather than > their data > > 2) I over-analyzed the issue before; my original > idea > > of using a PropertyNameMatchingCopier is > sufficient to > > copy indexed containers to maps, since a basic > > reflector will list the string versions of > available > > indices as property names. :) > > > Adding a more specific PropertyNameMatchingCopier > before the > ContainerCopier sounds like a good approach. A new > class should not be > needed. The Spring application context file that > comes bundled with > Morph and is located in > src\core\net\sf\morph\morphContext.xml should be > updated as well. > > Matt S > > > -Matt B > > > > --- Matt Benson <gud...@ya...> wrote: > > > > > >> SimpleDelegatingTransformer currently uses as its > >> last > >> two resorts a containerCopier and a > >> propertyNameMatchingCopier; attempting to convert > a > >> POJO to a map results in that object being added > to > >> the map with a null key (the container copier > does > >> this by assuming the POJO is a container with a > >> single > >> component). It is my assertion that the average > >> user > >> would rather want the POJO's properties mapped as > >> key-value pairs in the target map. > >> > >> My first instinct was to add a > >> PropertyNameMatchingCopier with its dest > class(es) > >> set > >> to Map.class just before ContainerCopier. But > then > >> I > >> realized that copying an indexed container to a > map > >> would be disabled that way. So I wrote an > >> ObjectToMapCopier which only matches Map > >> destinations > >> and extends SDT, delegating first to a > >> ContainerCopier > >> that only does indexed container reflection, then > to > >> a > >> PropertyNameMatchingCopier. So that it can be > used > >> beneath SDT, it implements NodeCopier. > >> > >> Copying > >> PropertyNameMatchingCopierTestCase.testCopy() to > >> DelegatingCopierTestCase shows that Morph > currently > >> does not implement this (IMO) reasonable behavior > by > >> default. By adding ObjectToMapCopier to SDT's > >> default > >> components list, just before ContainerCopier, we > can > >> convert POJOs to Maps while continuing to convert > >> indexed collections as expected. > >> > >> I would like to make this change. Any arguments > >> against my interpretation of the likely DWIM > >> interpretation of "copy this POJO to this Map"??? > >> > >> -Matt > >> > >> > >> > >> > >> > > > ____________________________________________________________________________________ > > > >> Expecting? Get great news right away with email > >> Auto-Check. > >> Try the Yahoo! Mail Beta. > >> > >> > > > http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html > > > >> > >> > > > ------------------------------------------------------------------------- > > > >> Take Surveys. Earn Cash. Influence the Future of > IT > >> Join SourceForge.net's Techsay panel and you'll > get > >> the chance to share your > >> opinions on IT & business topics through brief > >> surveys-and earn cash > >> > >> > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > >> _______________________________________________ > >> morph-developer mailing list > >> mor...@li... > >> > >> > > > https://lists.sourceforge.net/lists/listinfo/morph-developer > > > > > > > > > > > > > ____________________________________________________________________________________ > > Do you Yahoo!? > > Everyone is raving about the all-new Yahoo! Mail > beta. > > http://new.mail.yahoo.com > > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of > IT > > Join SourceForge.net's Techsay panel and you'll > get the chance to share your > > opinions on IT & business topics through brief > surveys-and earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > > morph-developer mailing list > > mor...@li... > > > https://lists.sourceforge.net/lists/listinfo/morph-developer > > > > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get > the chance to share your > opinions on IT & business topics through brief > surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > morph-developer mailing list > mor...@li... > https://lists.sourceforge.net/lists/listinfo/morph-developer > ____________________________________________________________________________________ The fish are biting. Get more visitors on your site using Yahoo! Search Marketing. http://searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php |