Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse code generator to generate mapper Class

I am trying to write a code generator do to Mapping between any two classes using Eclipse. The idea is to present a Wizard where users selects two classes whose properties need to be mapped. Then display all the potential matches and if user is okay then create a ClassMapper class where we will have only one method map which will do the required Class1.setXXX(Class2.getXXX());

Any pointers on how can we do this?

Thanks

like image 777
user667022 Avatar asked Nov 04 '22 08:11

user667022


1 Answers

This what you're going to do offers similar functionality as Dozer, but static code has this superiority, that it is faster, it contains logic only in code, and it is easier to find field usage via call hierarchy in IDE.

Generally the Eclipse plugin would be the best way to start, because you can only project GUI and the displaying is done by Eclipse itself, and also you hava access to its great tools to work with java code.

I think, however, the worse part would be the configuration one. Dozer has its primitive mapper (primitive in the way it converts between primitive and native java types ;) which handles most typical conversions between standard types, however there is ofted need to configure it. For example, the strings representing booleans can be either 't' and 'f', or 'true' and 'false' or '1' and '0', or words from other language. Dates can have various formats etc. So you would need to configure in this plugin various mappers, propably by the means of defining own code snippets to handle specific conversion.

However, if you do this, you will be greatly appreciated. I was recently searching for something, that would do even more, I mean it could both create mapping AND the dto's to which code will be matched, with possibility to merge class hierarchy for design, when object subtypes are represented by various classes, to flat single class, better for json transport, however, without result.

like image 102
Danubian Sailor Avatar answered Nov 09 '22 07:11

Danubian Sailor