Here is my User class :
@Data
@Entity
public class User {
@Id @GeneratedValue Long userID;
String eMail;
String phoneNumber;
String displayName;
//File displayPicture;
String firstName;
String middleName;
String lastName;
ArrayList<ClassRoom>adminOf=new ArrayList<>();
ArrayList<ClassRoom>memberOf=new ArrayList<>();
@NotNull
int rating;
boolean isTeacher;
ArrayList<Assignment>assignmentsToSubmit=new ArrayList<>();
ArrayList<Assignment>assignmentsSubmitted=new ArrayList<>();
@OneToOne(fetch = FetchType.LAZY,targetEntity = LoginCredential.class)
@JoinColumn(name = "userID",referencedColumnName = "userID")
private LoginCredential loginCredential;
User() {
}
}
And here is the controller, UserController class :
@RestController
class UserController {
private final UserRepository repository;
UserController(UserRepository repository) {
this.repository = repository;
}
@GetMapping("/user/{id}")
User one(@PathVariable Long id) {
return repository.findById(id).orElseThrow(() -> new UserNotFoundException(id));
}
}
I accessed http://localhost:8080/user/1 through my browser. Here it is the output :
Here loginCredential is also showing up, but I want to return everything except it.
How this can be done, without another class?

@Entityannotated classes when you call the database. Then you move over everything from that class to another class and this object you return to the browser (client). This way you can add stuff to database without affecting the browser object, or you can add things to the browser object without affecting the database.