开发者

Best way to help eliminate boilerplate when converting between data models

I'm working on a project where there are two sets of XML schema-generated objects which are two entirely different sets of classes with a similar structure. Conversion between the the two sets consists of a huge amount of boilerplate redundant coding (such as converting elements withing several nested layers of collections).

I'm interested in any reflection or bytecode generation based tool that might be able to take a set of declarative conversion rules and generate the necessary code.

This is for Java.


FYI: I know about commons-beanutils, copyProperties Field names, method names, and contained class types are all different, but at the lowest levels Strings, Enums, Integers开发者_如何学运维 and Dates can all be converted simply. A bean-pattern copy will not work.


I have been using dozer for this and works great. check it out @ http://dozer.sourceforge.net/


Try commons-beanutils. It has

  • BeanUtils.copyProperties(dest, source)
  • converters
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜