Код: Выделить всё
@Data
public class Parent {
long id;
String name;
public boolean isEmpty() {
return StringUtils.isEmpty(name);
}
Код: Выделить всё
@Data
public class Child extends Parent {
String nickName;
}
Код: Выделить всё
@Data
public class Grandchild extends Child {
int count;
}
Код: Выделить всё
@Data
public class ParentDto {
long idDto;
String name;
}
Код: Выделить всё
@Data
public class ChildDto extends ParentDto {
String nickNameDto;
}
Код: Выделить всё
@Data
public class GrandchildDto extends ChildDto {
int countDto;
}
Код: Выделить всё
@Mapper(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION)
public interface ParentMapper {
@SubclassMapping(target = GrandchildDto.class, source = Grandchild.class)
@SubclassMapping(target = ChildDto.class, source = Child.class)
@Mapping(target = "idDto", source = "id")
@BeanMapping(ignoreUnmappedSourceProperties = {"empty"}
ParentDto mapToParentDto(Parent parent)
}
Код: Выделить всё
@Mapper(uses = ParentMapper.class) ... not sure this is correct/necessary
public interface ChildMapper {
@SubclassMapping(target = GrandchildDto.class, source = Grandchild.class)
@Mapping(target = "nickNameDto", source = "nickName")
ChildDto mapToChildDto(Child child)
}
Код: Выделить всё
@Mapper(uses = ChildMapper.class) ... not sure this is correct/necessary
public interface GrandchildMapper {
@Mapping(target = "countDto", source = "count")
GrandchildDto mapToGrandChildDto(Grandchild grandchild)
}
Как лучше всего обрабатывать множественное наследование с разными именами параметров?
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/798 ... ed-classes
Мобильная версия