Source Class looks like:
Data
@Accessors(chain = true)
@Validated
public class OAuth2ClientCreateRequest {
@NotNull
Data data;
@lombok.Data
@Accessors(chain = true)
public static class Data {
@Pattern(regexp = "oauth2_clients")
private String type;
@NotNull
private OAuth2ClientAttributes attributes;
}
@lombok.Data
@Accessors(chain = true)
public static class OAuth2ClientAttributes {
@NotNull @Length(min = 10, max = 256)
private String clientId;
......
Target Class Looks like:
@Accessors(chain = true)
@Getter
@Setter
@ToString
public class OAuth2Client extends BaseEntity<OAuth2Client> implements Serializable {
@NotNull
@Length(min = 10, max = 256)
@JsonProperty
private String clientId;
........
Mapper Class:
@Mapper(componentModel = "spring")
public interface OAuth2ClientMapper {
@Mapping(target = "clientId", source = "attr.clientId")
OAuth2Client convert(OAuth2ClientCreateRequest.OAuth2ClientAttributes attr);
}
Errors I am getting while doing Maven Compile:
[ERROR] ....../OAuth2ClientMapper.java:[14,52] The type of parameter "attr" has no property named "clientId".
[ERROR] ....../OAuth2ClientMapper.java:[14,52] Unknown property "clientId" in result type .....oauth2authserver.domain.entity.OAuth2Client. Did you mean "null"?
Notice that I am using MapStruct with Lombok. Is there any preprocessor related issues here?
In my project in IntelliJ IDE, Lombok
was working without adding any annotation preprocessors because Lombok
plugin was downloaded through IntelliJ settings.
Then when it comes to adding map-struct
dependency in pom.xml, I had to add annotation preprocessor plugin mapstruct-processor
in pom.xml. Then Lombok
starts unable to work.
Finally adding annotation processors both for Lombok
and Map-Struct
like below works -
<properties>
<java.version>11</java.version>
<mapstruct.version>1.3.1.Final</mapstruct.version>
<gson.version>2.8.5</gson.version>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With