mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#3652 Inverse Inheritance should be possible for ignore-mappings without source
This commit is contained in:
parent
96d0698417
commit
b452d7f2c8
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
### Bugs
|
### Bugs
|
||||||
|
|
||||||
|
* Inverse Inheritance Strategy not working for ignored mappings only with target (#3652)
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
### Build
|
### Build
|
||||||
|
@ -479,13 +479,12 @@ public class MappingOptions extends DelegatingOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mapping can only be inversed if the source was not a constant nor an expression nor a nested property
|
* Mapping can only be inversed if the source was not a constant nor an expression
|
||||||
* and the mapping is not a 'target-source-ignore' mapping
|
|
||||||
*
|
*
|
||||||
* @return true when the above applies
|
* @return true when the above applies
|
||||||
*/
|
*/
|
||||||
public boolean canInverse() {
|
public boolean canInverse() {
|
||||||
return constant == null && javaExpression == null && !( isIgnored && sourceName == null );
|
return constant == null && javaExpression == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MappingOptions copyForInverseInheritance(SourceMethod templateMethod,
|
public MappingOptions copyForInverseInheritance(SourceMethod templateMethod,
|
||||||
|
@ -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._3652;
|
||||||
|
|
||||||
|
public class Bar {
|
||||||
|
|
||||||
|
private int secret;
|
||||||
|
private int doesNotExistInFoo;
|
||||||
|
|
||||||
|
public int getSecret() {
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecret(int secret) {
|
||||||
|
this.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDoesNotExistInFoo() {
|
||||||
|
return doesNotExistInFoo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDoesNotExistInFoo(int doesNotExistInFoo) {
|
||||||
|
this.doesNotExistInFoo = doesNotExistInFoo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* 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._3652;
|
||||||
|
|
||||||
|
public class Foo {
|
||||||
|
|
||||||
|
private int secret;
|
||||||
|
|
||||||
|
public int getSecret() {
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecret(int secret) {
|
||||||
|
this.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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._3652;
|
||||||
|
|
||||||
|
import org.mapstruct.InheritInverseConfiguration;
|
||||||
|
import org.mapstruct.MapperConfig;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.MappingInheritanceStrategy;
|
||||||
|
|
||||||
|
@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_ALL_FROM_CONFIG)
|
||||||
|
public interface FooBarConfig {
|
||||||
|
|
||||||
|
@Mapping(target = "doesNotExistInFoo", ignore = true)
|
||||||
|
@Mapping(target = "secret", ignore = true)
|
||||||
|
Bar toBar(Foo foo);
|
||||||
|
|
||||||
|
@InheritInverseConfiguration(name = "toBar")
|
||||||
|
Foo toFoo(Bar bar);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* 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._3652;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
@Mapper(config = FooBarConfig.class)
|
||||||
|
public interface FooBarMapper {
|
||||||
|
|
||||||
|
FooBarMapper INSTANCE = Mappers.getMapper( FooBarMapper.class );
|
||||||
|
|
||||||
|
Bar toBar(Foo foo);
|
||||||
|
|
||||||
|
Foo toFoo(Bar bar);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* 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._3652;
|
||||||
|
|
||||||
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
|
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@IssueKey("3652")
|
||||||
|
public class Issue3652Test {
|
||||||
|
|
||||||
|
@WithClasses({
|
||||||
|
Bar.class,
|
||||||
|
Foo.class,
|
||||||
|
FooBarConfig.class,
|
||||||
|
FooBarMapper.class,
|
||||||
|
})
|
||||||
|
@ProcessorTest
|
||||||
|
void ignoreMappingsWithoutSourceShouldBeInvertible() {
|
||||||
|
Bar bar = new Bar();
|
||||||
|
bar.setSecret( 123 );
|
||||||
|
bar.setDoesNotExistInFoo( 6 );
|
||||||
|
|
||||||
|
Foo foo = FooBarMapper.INSTANCE.toFoo( bar );
|
||||||
|
|
||||||
|
assertThat( foo.getSecret() ).isEqualTo( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user