0

I created a couple of DTO's and a MapStruct interface for getting the User data:

public class UserDto {
    private Long id;        
    private CountryDto country;
}

public class CountryDto {
    private Long id;
    private String name;
    
    private List<TimeZoneDto> timeZones = new ArrayList<TimeZoneDto>();
}

@Mapper
public interface UserMapper {
    UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);

    // TODO exclude country timezones
    UserDto mapToDto(User entity);
}

I would like to modify UserMapper so the CountryDto timezones list are excluded

{
   "id":1,
   "country": {
        "id": 182,
        "name":"Australia"
   }
}
txemix
  • 45
  • 9

1 Answers1

3

I finally found a solution for this, just adding the line below in UserMapper did the trick:

@Mapping(target = "country.timeZones", ignore = true)
UserDto mapToDto(User entity);
chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
txemix
  • 45
  • 9