Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

@SubclassMapping not working with @BeanMapping.ignoreUnmappedSourceProperties #3609

Copy link
Copy link

Description

@pemu69
Issue body actions

Expected behavior

@BeanMapping.ignoreUnmappedSourceProperties should not be ignored.

Actual behavior

I want to use @SubclassMapping and @BeanMapping.ignoreUnmappedSourceProperties on the same mapping method. The @BeanMapping.ignoreUnmappedSourceProperties seems to be ignored. If I remove the @SubclassMapping annotations the error (Unmapped source property: "id") disappears.

Steps to reproduce the problem

class Vehicle {
    public int price;
}

class Car extends Vehicle {
    public int seats;
}

class Truck extends Vehicle {
    public int capacity;
}

class VehicleDto {
    public int id;
    public int price;
}

class CarDto extends VehicleDto {
    public int seats;
}

class TruckDto extends VehicleDto {
    public int capacity;
}

@MapperConfig(
    unmappedSourcePolicy = ReportingPolicy.ERROR,
    unmappedTargetPolicy = ReportingPolicy.ERROR,
    subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION
)
class Config {
}
@Mapper(config = Config.class)
public abstract class VehicleMapper {

    @SubclassMapping(source = CarDto.class, target = Car.class)
    @SubclassMapping(source = TruckDto.class, target = Truck.class)
    @BeanMapping(ignoreUnmappedSourceProperties = { "id" })
    public abstract Vehicle toVehicle(VehicleDto vehicle);

    @InheritInverseConfiguration
    @Mapping(target = "id", ignore = true)
    public abstract VehicleDto toVehicleDto(Vehicle vehicle);
}

MapStruct Version

1.5.5

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.