开发者

Best way to help eliminate boilerplate when converting between data models

开发者 https://www.devze.com 2023-01-06 10:06 出处:网络
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 consis

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

精彩评论

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