Skip to content

Commit f439ab2

Browse files
committed
#1075, forge map to bean method
1 parent 1f41994 commit f439ab2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

processor/src/main/java/org/mapstruct/ap/internal/model/PropertyMapping.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ private Assignment forge( ) {
296296
else if ( sourceType.isMapType() && targetType.isMapType() ) {
297297
assignment = forgeMapMapping( sourceType, targetType, rightHandSide );
298298
}
299+
else if ( sourceType.isMapType() && !targetType.isMapType()) {
300+
assignment = forgeMapToBeanMapping( sourceType, targetType, rightHandSide );
301+
}
299302
else if ( ( sourceType.isIterableType() && targetType.isStreamType() )
300303
|| ( sourceType.isStreamType() && targetType.isStreamType() )
301304
|| ( sourceType.isStreamType() && targetType.isIterableType() ) ) {
@@ -690,6 +693,19 @@ private Assignment forgeMapMapping(Type sourceType, Type targetType, SourceRHS s
690693
return createForgedAssignment( source, methodRef, mapMappingMethod );
691694
}
692695

696+
private Assignment forgeMapToBeanMapping(Type sourceType, Type targetType, SourceRHS source) {
697+
698+
targetType = targetType.withoutBounds();
699+
ForgedMethod methodRef = prepareForgedMethod( sourceType, targetType, source, "{}" );
700+
701+
BeanMappingMethod.Builder builder = new BeanMappingMethod.Builder();
702+
final BeanMappingMethod mapToBeanMappingMethod = builder.mappingContext( ctx )
703+
.forgedMethod( methodRef )
704+
.build();
705+
706+
return createForgedAssignment( source, methodRef, mapToBeanMappingMethod );
707+
}
708+
693709
private Assignment forgeMapping(SourceRHS sourceRHS) {
694710
Type sourceType;
695711
if ( targetWriteAccessorType == AccessorType.ADDER ) {

processor/src/test/java/org/mapstruct/ap/test/frommap/MapToBeanFromMapAndNestedMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface MapToBeanFromMapAndNestedMap {
2121

2222
Target toTarget(Source source);
2323

24-
NestedTarget toNestedTarget(Map<String, String> nestedMap);
24+
//NestedTarget toNestedTarget(Map<String, String> nestedMap);
2525

2626
class Source {
2727

0 commit comments

Comments
 (0)