You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the superclass has a non-empty constructor, then MapStruct ignores the subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION option when generating code
For this example MapStruct generates the following code
@Override
public AbstractTarget map(AbstractSource source) {
if ( source == null ) {
return null;
}
if (source instanceof Source1) {
return source1ToTarget1( (Source1) source );
}
else if (source instanceof Source2) {
return source2ToTarget2( (Source2) source );
}
else {
String name = null;
name = source.getName();
AbstractTarget abstractTarget = new AbstractTarget( name );
return abstractTarget;
}
}
I was expecting a new IllegalArgumentException to be thrown in the last else statement. And also this generated code doesn't compile due to new AbstractTarget( name )
After some debugging, I think that if change the isAbstractReturnType method in the BeanMappingMethod#isAbstractReturnType class from
The text was updated successfully, but these errors were encountered:
prtnv
changed the title
The subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION option does not work if the superclass has a non-empty constructorSubclassExhaustiveStrategy.RUNTIME_EXCEPTION option does not work if the superclass has a non-empty constructor
Jun 16, 2022
If the superclass has a non-empty constructor, then MapStruct ignores the
subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION
option when generating codeMapStruct 1.5.1.Final, JDK 17
Reproduction scenario:
For this example MapStruct generates the following code
I was expecting a new IllegalArgumentException to be thrown in the last else statement. And also this generated code doesn't compile due to
new AbstractTarget( name )
After some debugging, I think that if change the
isAbstractReturnType
method in theBeanMappingMethod#isAbstractReturnType
class fromto
then everything will be fine
Can I try to create PR to fix it?
The text was updated successfully, but these errors were encountered: