-1

Let's say i have the following classes

class User {
   private String name:
   private Address address;
  // getters and setters
}

class UserDto {
   private String name:
   private Address address;
  // getters and setters
}

I already have created a modelMapper that allows me to do the following :

UserDto userDto = modelMapper.map(user, UserDto.class); // this map function map every field in the User class to UserDto class

And i would like to create a modelMapper that allows me to do the following :

UserDto userDto = modelMapper.mapWithoutAddress(user, UserDto.class); // this map function map every field except the adress from the User class to UserDto class

NB: i'am using a ModelMapper Singleton, i'm using the same instance in all my application.

1 Answers1

1

As the documentation said, you could skip the property.

modelMapper.typeMap(User.class, UserDto.class).addMappings(mapper -> mapper.skip(UserDto::setAddress));
Stone
  • 155
  • 1
  • 6
  • It works for one case, but since I am using a singleton of ModelMapper, this skip configuration impacts the first map method which doesn't map the address anymore. Ideally i would like a separate map method – Hassen Gaaya May 26 '23 at 09:59