Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown Property in a return type

I am trying to use mapstruct in my Play 2.4 Java8 JPA project. Steps I have done:

Added Dependency

  "org.mapstruct" % "mapstruct-jdk8" % "1.1.0.Beta1",
  "org.mapstruct" % "mapstruct-processor" % "1.1.0.Beta1"

Model

@Entity
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;            
    private String fullName;          
    private String email;
}

EmployeeDto

public class EmployeeDto {

    private String full_name;
    private String email;
}

EmployeeMapper

@Mapper
public interface EmployeeMapper {

    EmployeeMapper INSTANCE = Mappers.getMapper(EmployeeMapper.class);

    @Mapping(source = "fullName", target = "full_name")
    EmployeeDto employeeToEmployeeDto(Employee employee);
}

But its giving me a compilation error

 error: Unknown property "full_name" in return type.
[error]     @Mapping(source = "fullName", target = "full_name")

What could be the issue for the error?

like image 784
singhakash Avatar asked Jul 02 '16 17:07

singhakash


1 Answers

Additional case for other developers: If you use Lombok, maven uses only the MapStruct processor. So Lombok cannot generate the getters/setters. To resolve that, add the lombok dependency in the annotationProcessorPaths.

Also if you use Lombok 1.8.16 and above, you have to add lombok-mapstruct-binding too.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${compiler-plugin.version}</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
        <annotationProcessorPaths>
            <path>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>${org.mapstruct.version}</version>
            </path>
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${projectlombok.version}</version>
            </path>
            <!-- This is needed when using Lombok 1.8.16 and above -->
            <path>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-mapstruct-binding</artifactId>
                <version>0.1.0</version>
            </path>
        </annotationProcessorPaths>
    </configuration>
</plugin>
like image 183
enesoral Avatar answered Sep 23 '22 17:09

enesoral