mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
parent
b3023b3902
commit
1cb8291fb9
@ -55,7 +55,7 @@ public class BeanMapping {
|
|||||||
beanMapping.nullValuePropertyMappingStrategy,
|
beanMapping.nullValuePropertyMappingStrategy,
|
||||||
beanMapping.nullValueCheckStrategy,
|
beanMapping.nullValueCheckStrategy,
|
||||||
beanMapping.reportingPolicy,
|
beanMapping.reportingPolicy,
|
||||||
false,
|
beanMapping.ignoreByDefault,
|
||||||
beanMapping.ignoreUnmappedSourceProperties,
|
beanMapping.ignoreUnmappedSourceProperties,
|
||||||
beanMapping.builder,
|
beanMapping.builder,
|
||||||
beanMapping.mirror
|
beanMapping.mirror
|
||||||
|
@ -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._1933;
|
||||||
|
|
||||||
|
import org.mapstruct.BeanMapping;
|
||||||
|
import org.mapstruct.MapperConfig;
|
||||||
|
import org.mapstruct.MappingInheritanceStrategy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
|
||||||
|
public interface Issue1933Config {
|
||||||
|
|
||||||
|
@BeanMapping(ignoreByDefault = true)
|
||||||
|
Entity updateEntity(Dto dto);
|
||||||
|
|
||||||
|
class Entity {
|
||||||
|
//CHECKSTYLE:OFF
|
||||||
|
public String id;
|
||||||
|
public int updateCount;
|
||||||
|
//CHECKSTYLE:ON
|
||||||
|
}
|
||||||
|
|
||||||
|
class Dto {
|
||||||
|
//CHECKSTYLE:OFF
|
||||||
|
public String id;
|
||||||
|
public int updateCount;
|
||||||
|
//CHECKSTYLE:ON
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* 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._1933;
|
||||||
|
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
@Mapper(config = Issue1933Config.class)
|
||||||
|
public interface Issue1933Mapper {
|
||||||
|
|
||||||
|
Issue1933Mapper INSTANCE = Mappers.getMapper( Issue1933Mapper.class );
|
||||||
|
|
||||||
|
@Mapping(target = "updateCount", source = "updateCount")
|
||||||
|
Issue1933Config.Entity map(Issue1933Config.Dto dto);
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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._1933;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
|
import org.mapstruct.ap.testutil.WithClasses;
|
||||||
|
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Sjaak Derksen
|
||||||
|
*/
|
||||||
|
@IssueKey("1933")
|
||||||
|
@RunWith(AnnotationProcessorTestRunner.class)
|
||||||
|
@WithClasses({
|
||||||
|
Issue1933Config.class,
|
||||||
|
Issue1933Mapper.class
|
||||||
|
})
|
||||||
|
public class Issue1933Test {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldIgnoreIdAndMapUpdateCount() {
|
||||||
|
|
||||||
|
Issue1933Config.Dto dto = new Issue1933Config.Dto();
|
||||||
|
dto.id = "id";
|
||||||
|
dto.updateCount = 5;
|
||||||
|
|
||||||
|
Issue1933Config.Entity entity = Issue1933Mapper.INSTANCE.map( dto );
|
||||||
|
|
||||||
|
assertThat( entity.id ).isNull();
|
||||||
|
assertThat( entity.updateCount ).isEqualTo( 5 );
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ public interface BuilderIgnoringMapper {
|
|||||||
BuilderIgnoringMapper INSTANCE = Mappers.getMapper( BuilderIgnoringMapper.class );
|
BuilderIgnoringMapper INSTANCE = Mappers.getMapper( BuilderIgnoringMapper.class );
|
||||||
|
|
||||||
@InheritConfiguration(name = "mapBase")
|
@InheritConfiguration(name = "mapBase")
|
||||||
|
@Mapping( target = "lastName" )
|
||||||
Person mapWithIgnoringBase(PersonDto source);
|
Person mapWithIgnoringBase(PersonDto source);
|
||||||
|
|
||||||
@BeanMapping(ignoreByDefault = true)
|
@BeanMapping(ignoreByDefault = true)
|
||||||
|
@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
public class BuilderIgnoringTest {
|
public class BuilderIgnoringTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@IssueKey( "1933" )
|
||||||
public void shouldIgnoreBase() {
|
public void shouldIgnoreBase() {
|
||||||
PersonDto source = new PersonDto();
|
PersonDto source = new PersonDto();
|
||||||
source.setId( 100L );
|
source.setId( 100L );
|
||||||
@ -38,7 +39,7 @@ public class BuilderIgnoringTest {
|
|||||||
Person target = BuilderIgnoringMapper.INSTANCE.mapWithIgnoringBase( source );
|
Person target = BuilderIgnoringMapper.INSTANCE.mapWithIgnoringBase( source );
|
||||||
|
|
||||||
assertThat( target.getId() ).isNull();
|
assertThat( target.getId() ).isNull();
|
||||||
assertThat( target.getName() ).isEqualTo( "John" );
|
assertThat( target.getName() ).isNull();
|
||||||
assertThat( target.getLastName() ).isEqualTo( "Doe" );
|
assertThat( target.getLastName() ).isEqualTo( "Doe" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public class IgnorePropertyTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("1392")
|
@IssueKey("1933")
|
||||||
public void shouldIgnoreBase() {
|
public void shouldIgnoreBase() {
|
||||||
|
|
||||||
WorkBenchDto workBenchDto = new WorkBenchDto();
|
WorkBenchDto workBenchDto = new WorkBenchDto();
|
||||||
@ -67,7 +67,7 @@ public class IgnorePropertyTest {
|
|||||||
WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBench( workBenchDto );
|
WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBench( workBenchDto );
|
||||||
|
|
||||||
assertThat( benchTarget ).isNotNull();
|
assertThat( benchTarget ).isNotNull();
|
||||||
assertThat( benchTarget.getArticleName() ).isEqualTo( "MyBench" );
|
assertThat( benchTarget.getArticleName() ).isNull();
|
||||||
assertThat( benchTarget.getDescription() ).isEqualTo( "Beautiful" );
|
assertThat( benchTarget.getDescription() ).isEqualTo( "Beautiful" );
|
||||||
assertThat( benchTarget.getKey() ).isNull();
|
assertThat( benchTarget.getKey() ).isNull();
|
||||||
assertThat( benchTarget.getModificationDate() ).isNull();
|
assertThat( benchTarget.getModificationDate() ).isNull();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user