에러

[에러] ModelMapper 사용 시 Method threw 'org.modelmapper.ConfigurationException' exception 에러 해결방법

nan2 2023. 1. 21. 14:35
반응형

 

MoelMapper를 그냥 new ModelMapper().map() 으로 사용할 경우 매핑 전략의 기본값은 타입만 맞으면 매핑된다.

그렇기 때문에 매핑 전략을 아래와 같이 STRICT로 해주면 해결!!

 

public ResponseEntity<User> getUser(@PathVariable(name = "userId") String userId) {
    ...
    
    ModelMapper mapper = new ModelMapper();
    mapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
    UserDto user = mapper.map(user, UserDto.class);
    
    ...
}
반응형