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?
The bean on the target side needs to have setters for the mapped properties.
MapStruct doesn't use reflection to get or set state in the mapped types, plain getter/setter calls are used in the generated code to propagate state from source to target.