Feb 17th, 2011, 04:33 PM
Automatic Data Transfer Object (DTO) Creation
I've decided to use DTOs to transfer my data to the view layer. My data is stored in persisted domain objects with bean style getters. I'd like to convert the data to a map of property value pairs (and later XML). I'd also like to recurse a specified depth into any referenced objects.
Before I reinvent the wheel is there anythings that does this for me, i.e. a method like:
Obect myBean = getBean();
Map<String,Object> model = FooBar.convert(myBean);
Where the Object is either a String value or a reference to another map or list.
I get the feeling that Spring or Apache commons provides something like this but I haven't quite found it yet.
Feb 17th, 2011, 10:24 PM
If you need to go deep, mapping frameworks like Dozer are helpful for this sort of thing.
If your mapping is pretty shallow some simple reflection, code generation or commons beanutils will suffice.
Tags for this Thread