ModelMapper configured/used for speed?

424 views
Skip to first unread message

John Smith

unread,
Nov 19, 2012, 6:32:57 PM11/19/12
to model...@googlegroups.com
ModelMapper.com's 'Getting Started' section provides a simple, straight-forward, zero configuration example...

ModelMapper modelMapper = new ModelMapper();
OrderDTO orderDTO = modelMapper.map(order, OrderDTO.class);

If I'm willing to "configure" the ModelMapper before I use it or use it differently than the examples...what can I do to make it go fast?

J

Jonathan Halterman

unread,
Nov 19, 2012, 6:39:36 PM11/19/12
to model...@googlegroups.com
There aren't really any specific optimizations for speed, except that it is recommended to reuse/share ModelMapper instances where possible as opposed to re-creating them each time you need to map something. The only time you wouldn't re-use a ModelMapper instance is if you needed to setup different mappings between the same source and destination types for different use cases.


Configuring ModelMapper prior to use is more about getting your properties correctly mapped than speed optimization.

Cheers,
Jonathan

Jonathan Halterman

unread,
Nov 20, 2012, 12:07:16 AM11/20/12
to model...@googlegroups.com
One more way to speed things up, actually: If your source and destination objects have property names that match each other exactly, such as:

order.customer.address.streetName -> orderDTO.customer.address.streetName

...then you can use the EXACT matching strategy (MatchingStrategies.EXACT) which will speed up the matching process a bit. Keep in mind, the matching process where source and destination properties are matched to each other only occurs once per source/destination type pair, per ModelMapper instance (which is why re-using the ModelMapper instance is a win). So you're only a saving a bit on performance the first time matches these two types, but still I thought I'd mention it.

Cheers,
Jonathan
Reply all
Reply to author
Forward
0 new messages