I have a basic SpringBoot 2.0.6.RELEASE app. Using Spring Initializer, JPA, embedded Tomcat, Thymeleaf template engine, and package as an executable JAR with a restful architecture I have this object:
public class Menu implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private Long id;
@Override
public int hashCode() {
return (int) (id ^ (id >>> 32));
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Menu menu = (Menu) o;
return id == menu.id;
}
...
}
I also have this piece of code in the controller:
List<Menu> favoriteMenus = new ArrayList<Menu>();
favoriteMenus.addAll(user.getFavoriteMenus());
favoriteMenus.addAll(applicationProfileService
.menusByProfile(user.getApplicationSetup().getApplicationProfile().getProfileKey()));
favoriteMenus =
favoriteMenus
.stream()
.distinct()
.collect(Collectors.toList());
but despite of distinct()
there are repeated menus in the list