// Driver model
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Driver {
private String driverName;
private String licenseNumber;
}
// Car model
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Car {
private String make;
private List<Driver> drivers;
private CarType type;
}
// Car DTO
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CarDto {
private String make;
private Integer totalDrivers;
private String type;
}
@Mapper
public interface CarMapper {
@Mapping(target = "totalDrivers", expression = "java(mapDrivers(car.getDrivers()))")
CarDto mapCarDto(Car car);
default Integer mapDrivers(List<Driver> totalDrivers) {
return totalDrivers.size();
}
@InheritInverseConfiguration
@Mapping(target = "drivers", ignore = true)
Car mapDtoToCar(CarDto carDto);
}
When I RUN this project those errors are reported:
..\CarMapper.java
java: Unknown property "totalDrivers" in result type CarDto. Did you mean "null"?
java: Unknown property "drivers" in result type Car. Did you mean "null"?
How can I get solve this problem?