[morph-developer] Copying Objects to Maps
Brought to you by:
orangeherbert,
sgarlatm
|
From: Matt B. <gud...@ya...> - 2007-02-23 20:56:53
|
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 |