Skip to content

Commit a95d1c5

Browse files
authored
mapstruct#2505 deepclone generates enum mapping method (mapstruct#2507)
1 parent 38744d9 commit a95d1c5

4 files changed

Lines changed: 120 additions & 0 deletions

File tree

processor/src/main/java/org/mapstruct/ap/internal/processor/creation/MappingResolverImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ private boolean allowDirect(Type type) {
383383
return true;
384384
}
385385

386+
if ( type.isEnumType() ) {
387+
return true;
388+
}
389+
386390
if ( type.isArrayType() ) {
387391
return type.isJavaLangType() || type.getComponentType().isPrimitive();
388392
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._2505;
7+
8+
import org.mapstruct.Mapper;
9+
import org.mapstruct.control.DeepClone;
10+
import org.mapstruct.factory.Mappers;
11+
12+
/**
13+
* @author Sjaak Derksen
14+
*/
15+
@Mapper( mappingControl = DeepClone.class )
16+
public interface Issue2505Mapper {
17+
18+
Issue2505Mapper INSTANCE = Mappers.getMapper( Issue2505Mapper.class );
19+
20+
Customer map(CustomerDTO value);
21+
22+
enum Status {
23+
ENABLED, DISABLED,
24+
}
25+
26+
class Customer {
27+
28+
private Status status;
29+
30+
public Status getStatus() {
31+
return status;
32+
}
33+
34+
public void setStatus(Status stat) {
35+
this.status = stat;
36+
}
37+
}
38+
39+
class CustomerDTO {
40+
41+
private Status status;
42+
43+
public Status getStatus() {
44+
return status;
45+
}
46+
47+
public void setStatus(Status status) {
48+
this.status = status;
49+
}
50+
}
51+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._2505;
7+
8+
import org.junit.jupiter.api.extension.RegisterExtension;
9+
import org.mapstruct.ap.testutil.IssueKey;
10+
import org.mapstruct.ap.testutil.ProcessorTest;
11+
import org.mapstruct.ap.testutil.WithClasses;
12+
import org.mapstruct.ap.testutil.runner.GeneratedSource;
13+
14+
import static org.assertj.core.api.Assertions.assertThat;
15+
16+
/**
17+
* @author Sjaak derksen
18+
*/
19+
@IssueKey("2505")
20+
@WithClasses( Issue2505Mapper.class )
21+
class Issue2505Test {
22+
23+
@RegisterExtension
24+
final GeneratedSource generatedSource = new GeneratedSource()
25+
.addComparisonToFixtureFor( Issue2505Mapper.class );
26+
27+
@ProcessorTest
28+
void shouldNotGenerateEnumMappingMethodForDeepClone() {
29+
Issue2505Mapper.CustomerDTO source = new Issue2505Mapper.CustomerDTO();
30+
source.setStatus( Issue2505Mapper.Status.DISABLED );
31+
32+
Issue2505Mapper.Customer target = Issue2505Mapper.INSTANCE.map( source );
33+
34+
assertThat( target.getStatus() ).isEqualTo( Issue2505Mapper.Status.DISABLED );
35+
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.ap.test.bugs._2505;
7+
8+
import javax.annotation.Generated;
9+
10+
@Generated(
11+
value = "org.mapstruct.ap.MappingProcessor",
12+
date = "2021-07-03T14:21:53+0200",
13+
comments = "version: , compiler: Eclipse JDT (Batch) 3.20.0.v20191203-2131, environment: Java 1.8.0_181 (Oracle Corporation)"
14+
)
15+
public class Issue2505MapperImpl implements Issue2505Mapper {
16+
17+
@Override
18+
public Customer map(CustomerDTO value) {
19+
if ( value == null ) {
20+
return null;
21+
}
22+
23+
Customer customer = new Customer();
24+
25+
customer.setStatus( value.getStatus() );
26+
27+
return customer;
28+
}
29+
}

0 commit comments

Comments
 (0)