Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

@Mapper
public interface StudentMapper<DomainBuilder> {
     StudentDomain toStudentDomain(String studentId, StudentRequest studentRequest, @MappingTarget DomainBuilder domainBuilder);
}
_________________________________
StudentController.java
@PutMapping("/{studentId})"
public StudentResponse update(@PathVariable studentId, @RequestBody studentRequest){
   StudentDomain currentStudentDomain = this.studentMapper.getStudent(studentId);
   StudentDomain studentDomain = this.studentMapper.toStudentDomain(studentId, studentRequest, currentStudentDomain .toBuilder());
   StudentDomain updatedStudentDomain = this.studentService.update(studentId, studentDomain);
   return this.studentMapper.toDto(updatedStudentDomain); 
}
___
Student.java

@Builder(toBuilder=true)
public Student {
....
}

I am trying to parse in generic i.e. DomainBuilder to the StudentMapper. However, the compiler throws error at this.studentMapper.toStudentDomain, saying 'Únchecked call to toStudentDomain as a member of raw type'. Can anyone advise what am I doing wrong here?

You must be logged in to vote

Replies: 1 comment

Comment options

The StudentMapper interface is declared with a generic type parameter DomainBuilder. In controller, when you are using this.studentMapper.toStudentDomain you are not mentioning DomainBuilder - so the compiler is thinking StudentMapper as a raw type and resulting this error.
To fix this, in your controller, the StudentMapper should be declared with StudentDomain.StudentDomainBuilder type to ensure the compiler its actual generic type.

StudentBuilder is generated by the use of lombok @Builder(toBuilder=true) upon Student. The toBuilder=true part of the annotation will create a new toBuilder() under the current object's value. Thus, currentStudentDomain.toBuilder() in your StudentController code returns an instance of StudentDomain.StudentDomainBuilder

So, the studentMapper should be declared as the actual type not the raw type-

private final StudentMapper<StudentDomain.StudentDomainBuilder> studentMapper; in controller class.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.