0

I have Result entity and User entity and they are linked via @OneToOne annotation:

@OneToOne
@MapsId
private User user;

and

@OneToOne(mappedBy = "user", cascade = CascadeType.ALL)
private Result result;

but when I try to get all results via ajax:

resultRepo.findAll()

results are coming with users with all user fields including password and etc. How to get only specific fields from User entity when I request all results ?

Alan Hay
  • 22,665
  • 4
  • 56
  • 110
socm_
  • 783
  • 11
  • 28

1 Answers1

0

Use @JsonIgnore on your field and it will not show in json repsonse

Soheil Rahsaz
  • 719
  • 7
  • 22
  • Hey, Thank you for the solution. It's works. But what about if a Entity is used by other places and there do not want to use JsonIgnore. – Rohit Sharma Sep 18 '22 at 04:03
  • If you have a different structure for your response, then you might wanna have a different DTO, @RohitSharma – Soheil Rahsaz Sep 18 '22 at 06:32