I'm trying to use MapStruct to map convert between dto and entity objects, however the generated mapper implementation only returns empty mapped object.
BeerMapperImpl
@Generated(
value = "org.mapstruct.ap.MappingProcessor",
date = "2020-11-05T07:42:21+0800",
comments = "version: 1.3.0.Final, compiler: javac, environment: Java 11 (Oracle Corporation)"
)
@Component
public class BeerMapperImpl implements BeerMapper {
@Override
public BeerDto beerToBeerDto(Beer beer) {
if ( beer == null ) {
return null;
}
BeerDto beerDto = new BeerDto();
return beerDto;
}
}
Below are my codes.
pom.xml
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.3.0.Final</version>
</dependency>
.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.3.0.Final</version>
</path>
<path>
<groupId>
org.projectlombok
</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<compilerArg>
-Amapstruct.defaultComponentModel=spring
</compilerArg>
</compilerArgs>
</configuration>
</plugin>
BeerMapper.java
@Mapper(uses = {DateMapper.class})
public interface BeerMapper {
BeerDto beerToBeerDto(Beer beer);
Beer beerDtoToBeer(Beer dto);
}
Anyone can help to advise what might go wrong in my codes? Thanks!
I resolved this issue after downgrading spring boot starter from 2.3.5.RELEASE to 2.1.5.RELEASE.