I'm aware that MapStruct can ignore unmapped properties and specific target properties, but is it possible to exlcude a property based on its actual value?
I have boolean fields which I would like to exclude only if they are false.
Thanks in advance!
Example:
Entity:
@Entity
@Table(name = "vehicle")
@Getter @Setter
public class Vehicle {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private boolean hasWheels;
private boolean hasWings;
private boolean hasBrakes;
}
DTO:
@Getter @Setter
public class VehicleDTO {
private String name;
private boolean hasWheels;
private boolean hasWings;
private boolean hasBrakes;
}
MapStruct Mapper:
@Mapper(componentModel = "spring")
public interface VehicleMapper {
// Entity to DTO:
VehicleDTO toVehicleDTO(Vehicle vehicle);
List<VehicleDTO> toVehicleDTOs(List<Vehicle> vehicles);
// DTO to Entity:
Vehicle toVehicle(VehicleDTO vehicleDTO);
}
I would like to fully exclude the boolean variables only if their value is "false".