static void mapExplicitly ( ) { Order order = createOrder ( ) ; ModelMapper modelMapper = new ModelMapper ( ) ; modelMapper . addMappings ( new PropertyMap < Order , OrderDTO > ( ) { @ Override protected void configure ( ) { map ( ) . setBillingStreet ( source . getBillingAddress ( ) . getStreet ( ) ) ; map ( source . billingAddress . getCity ( ) , destination . billingCity ) ; } } ) ; OrderDTO orderDTO = modelMapper . map ( order , OrderDTO . class ) ; assertOrdersEqual ( order , orderDTO ) ; }
This example demonstrates how ModelMapper can be used to explicitly map properties from an Order to OrderDTO .