laban_luka
laban_luka

Reputation: 609

MapStruct casts error incompatible types: cannot be converted to

Not sure what happens here but when I do mvn clean install I get following error:

incompatible types: capture#1 of ? cannot be converted to com.sweetchoice.report.entities.WhoDelivers

Mapper class:

@Mapper(uses = {BaseJournalMapper.class})
public interface WhoDeliversMapper {

    WhoDelivers dtoToEntity(WhoDeliversDto whoDeliversDto);

    WhoDeliversDto entityToDto(WhoDelivers whoDelivers);
}

Entity class:

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "who_delivers")
public class WhoDelivers extends BaseJournalEntity{

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(columnDefinition = "serial")
    private Long id;

    private String name;
}

BaseJournalEntity/BaseJournalDto:

@Getter
@Setter
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
@MappedSuperclass
public class BaseJournalDto {

    private LocalDateTime createdAt;
    private Long createdBy;
    private LocalDateTime updatedAt;
    private Long updatedBy;
}

DTO class:

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class WhoDeliversDto extends BaseJournalDto{

    private Long id;

    private String name;

}

and finally pom.xml:

     <dependency>
            <groupId>org.mapstruct</groupId>
            <artifactId>mapstruct</artifactId>
            <version>${mapstruct.version}</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <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>
                        <path>
                            <groupId>org.projectlombok</groupId>
                            <artifactId> lombok-mapstruct-binding</artifactId>
                            <version>0.1.0</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs>
                        <compilerArg>-Amapstruct.defaultComponentModel=spring</compilerArg>
                    </compilerArgs>
                </configuration>
            </plugin>
enter code here

I'm using Java 11, MapStruct 1.4.1.Final and Lombok 1.18.16

Upvotes: 1

Views: 3610

Answers (1)

laban_luka
laban_luka

Reputation: 609

Answer :

Found an answer on my own.

Just add @SuperBuilder in Entity and DTO classes. More info on this link Documentation

Upvotes: 3

Related Questions