I have an entity Movies and an entity Genres in a relationship many to many.
@ManyToMany
@JoinTable(name = "movies_genres", joinColumns = @JoinColumn(name = "movies_id"), inverseJoinColumns = @JoinColumn(name = "genres_id"))
private Set<Genres> genresSet = new HashSet<>();
In a rest controller class, I want to do this:
@GetMapping("/search-movies")
public Iterable<Movies> search(
@RequestParam(value = "genresSet", required = false) Set<Genres> genresSet,
@RequestParam(value = "synopsis", required = false) String synopsis,
@RequestParam(value = "title", required = false) String title,
@RequestParam(value = "runtime", required = false) Integer runtime
)
I use axios on front-end to send params to the back-end and genresSet
is array of objects, for example
[
{ id: 1, name: 'action'},
{ id: 2, name: 'crime'},
{ id: 3, name: 'comedy'}
]
I thought that Spring would automatically convert array of objects into set of genres, but it gives me null.
How to get values of genres in form of a set of values?
To recap, the user enters more than one genre, where each genre is represented as an object, so front-end sends array of genre objects and back-end needs to bind that array to the set of genres, where set of genres is a many to many property of Movie entity.