mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
parent
ded8d88c73
commit
bd2c206f7f
@ -63,6 +63,9 @@ public class SetterWrapperForCollectionsAndMapsWithNullCheck extends WrapperForC
|
||||
if (isDirectAssignment() || getSourcePresenceCheckerReference() == null ) {
|
||||
imported.addAll( getNullCheckLocalVarType().getImportTypes() );
|
||||
}
|
||||
if ( isMapNullToDefault() && ( targetType.getImplementationType() != null ) ) {
|
||||
imported.add( targetType.getImplementationType() );
|
||||
}
|
||||
return imported;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
/*
|
||||
* 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._1590;
|
||||
|
||||
public class Book {
|
||||
}
|
@ -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._1590;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface BookMapper {
|
||||
|
||||
BookMapper INSTANCE = Mappers.getMapper( BookMapper.class );
|
||||
|
||||
Book map(Book book);
|
||||
|
||||
List<Book> map(List<Book> books);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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._1590;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BookShelf {
|
||||
private List<Book> books;
|
||||
|
||||
public List<Book> getBooks() {
|
||||
return books;
|
||||
}
|
||||
|
||||
public void setBooks(List<Book> books) {
|
||||
this.books = books;
|
||||
}
|
||||
}
|
@ -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._1590;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.NullValueCheckStrategy;
|
||||
import org.mapstruct.NullValueMappingStrategy;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper(uses = BookMapper.class,
|
||||
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
|
||||
nullValueMappingStrategy = NullValueMappingStrategy.RETURN_DEFAULT)
|
||||
public interface BookShelfMapper {
|
||||
|
||||
BookShelfMapper INSTANCE = Mappers.getMapper( BookShelfMapper.class );
|
||||
|
||||
BookShelf map(BookShelf bookShelf);
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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._1590;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
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
|
||||
*/
|
||||
@WithClasses({
|
||||
BookMapper.class,
|
||||
BookShelfMapper.class,
|
||||
Book.class,
|
||||
BookShelf.class
|
||||
})
|
||||
@RunWith(AnnotationProcessorTestRunner.class)
|
||||
@IssueKey("1590")
|
||||
public class Issue1590Test {
|
||||
|
||||
@Test
|
||||
public void shouldTestMappingLocalDates() {
|
||||
BookShelf source = new BookShelf();
|
||||
source.setBooks( Arrays.asList( new Book() ) );
|
||||
|
||||
BookShelf target = BookShelfMapper.INSTANCE.map( source );
|
||||
|
||||
assertThat( target ).isNotNull();
|
||||
assertThat( target.getBooks() ).isNotNull();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user