I have the following Mappings
@Mappings({
@Mapping(source = \"id\", target = \"id\"),
@Mapping(source = \"childId\", target = \"child.id\")
})
E
Found not a very elegant solution as for me but working solution.
First change interface to abstract class then add @AfterMapping
@Mappings({
@Mapping(source = "id", target = "id"),
@Mapping(source = "childId", target = "child.id")
})
public abstract Entity objectDtoToEntity(ObjectDTO objectDTO);
@AfterMapping
public Entity doAfterMapping(@MappingTarget Entity entity) {
if (entity != null && entity.getChild().getId() == null) {
entity.setChild(null);
}
return entity;
}