mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3668 Do not apply implicit mappings when using SubclassExhaustiveStrategy#RUNTIME_EXCEPTION
and return type is abstract
This commit is contained in:
parent
6c8a2e184b
commit
c89b616f8c
@ -5,6 +5,7 @@
|
|||||||
### Bugs
|
### Bugs
|
||||||
|
|
||||||
* Inverse Inheritance Strategy not working for ignored mappings only with target (#3652)
|
* Inverse Inheritance Strategy not working for ignored mappings only with target (#3652)
|
||||||
|
* Inconsistent ambiguous mapping method error when using `SubclassMapping`: generic vs raw types (#3668)
|
||||||
* Fix regression when using `InheritInverseConfiguration` with nested target properties and reversing `target = "."` (#3670)
|
* Fix regression when using `InheritInverseConfiguration` with nested target properties and reversing `target = "."` (#3670)
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
@ -295,7 +295,9 @@ public class BeanMappingMethod extends NormalTypeMappingMethod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean applyImplicitMappings = !mappingReferences.isRestrictToDefinedMappings();
|
// If defined mappings should not be handled then we should not apply implicit mappings
|
||||||
|
boolean applyImplicitMappings =
|
||||||
|
shouldHandledDefinedMappings && !mappingReferences.isRestrictToDefinedMappings();
|
||||||
if ( applyImplicitMappings ) {
|
if ( applyImplicitMappings ) {
|
||||||
applyImplicitMappings = beanMapping == null || !beanMapping.isignoreByDefault();
|
applyImplicitMappings = beanMapping == null || !beanMapping.isignoreByDefault();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3668;
|
||||||
|
|
||||||
|
public abstract class Child {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ChildA extends Child { }
|
||||||
|
|
||||||
|
public static class ChildB extends Child { }
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3668;
|
||||||
|
|
||||||
|
public abstract class ChildDto {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ChildDtoA extends ChildDto { }
|
||||||
|
|
||||||
|
public static class ChildDtoB extends ChildDto { }
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3668;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.SubclassExhaustiveStrategy;
|
||||||
|
import org.mapstruct.SubclassMapping;
|
||||||
|
|
||||||
|
@Mapper(subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION)
|
||||||
|
public interface ChildMapper {
|
||||||
|
|
||||||
|
@SubclassMapping(target = Child.ChildA.class, source = ChildDto.ChildDtoA.class)
|
||||||
|
@SubclassMapping(target = Child.ChildB.class, source = ChildDto.ChildDtoB.class)
|
||||||
|
Child toEntity(ChildDto childDto);
|
||||||
|
|
||||||
|
@SubclassMapping(target = ChildDto.ChildDtoA.class, source = Child.ChildA.class)
|
||||||
|
@SubclassMapping(target = ChildDto.ChildDtoB.class, source = Child.ChildB.class)
|
||||||
|
ChildDto toDto(Child child);
|
||||||
|
|
||||||
|
Child.ChildA toEntity(ChildDto.ChildDtoA childDto);
|
||||||
|
|
||||||
|
ChildDto.ChildDtoA toDto(Child.ChildA child);
|
||||||
|
|
||||||
|
Child.ChildB toEntity(ChildDto.ChildDtoB childDto);
|
||||||
|
|
||||||
|
ChildDto.ChildDtoB toDto(Child.ChildB child);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3668;
|
||||||
|
|
||||||
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
|
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@IssueKey("3668")
|
||||||
|
@WithClasses({
|
||||||
|
Child.class,
|
||||||
|
ChildDto.class,
|
||||||
|
ChildMapper.class,
|
||||||
|
Parent.class,
|
||||||
|
ParentDto.class,
|
||||||
|
ParentMapper.class,
|
||||||
|
})
|
||||||
|
class Issue3668Test {
|
||||||
|
|
||||||
|
@ProcessorTest
|
||||||
|
void shouldCompile() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3668;
|
||||||
|
|
||||||
|
public abstract class Parent<T extends Child> {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private T child;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getChild() {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChild(T child) {
|
||||||
|
this.child = child;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ParentA extends Parent<Child.ChildA> { }
|
||||||
|
|
||||||
|
public static class ParentB extends Parent<Child.ChildB> { }
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3668;
|
||||||
|
|
||||||
|
public abstract class ParentDto<T extends ChildDto> {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private T child;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getChild() {
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChild(T child) {
|
||||||
|
this.child = child;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ParentDtoA extends ParentDto<ChildDto.ChildDtoA> { }
|
||||||
|
|
||||||
|
public static class ParentDtoB extends ParentDto<ChildDto.ChildDtoB> { }
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.ap.test.bugs._3668;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.SubclassExhaustiveStrategy;
|
||||||
|
import org.mapstruct.SubclassMapping;
|
||||||
|
|
||||||
|
@Mapper(uses = { ChildMapper.class }, subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION)
|
||||||
|
public interface ParentMapper {
|
||||||
|
|
||||||
|
@SubclassMapping(target = Parent.ParentA.class, source = ParentDto.ParentDtoA.class)
|
||||||
|
@SubclassMapping(target = Parent.ParentB.class, source = ParentDto.ParentDtoB.class)
|
||||||
|
Parent<?> toEntity(ParentDto<?> parentDto);
|
||||||
|
|
||||||
|
@SubclassMapping(target = ParentDto.ParentDtoA.class, source = Parent.ParentA.class)
|
||||||
|
@SubclassMapping(target = ParentDto.ParentDtoB.class, source = Parent.ParentB.class)
|
||||||
|
ParentDto<?> toDto(Parent<?> parent);
|
||||||
|
|
||||||
|
Parent.ParentA toEntity(ParentDto.ParentDtoA parentDto);
|
||||||
|
|
||||||
|
ParentDto.ParentDtoA toDto(Parent.ParentA parent);
|
||||||
|
|
||||||
|
Parent.ParentB toEntity(ParentDto.ParentDtoB parentDto);
|
||||||
|
|
||||||
|
ParentDto.ParentDtoB toDto(Parent.ParentB parent);
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user