1



I have Film and Genre entities. Both of them have associations that refer to each other's classes:

@Data
@Entity
public class Film {

    @Id
    @Column(name = "film_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long filmId;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "film_genres",
            joinColumns = @JoinColumn(name = "film_id", referencedColumnName = "film_id"),
            inverseJoinColumns = @JoinColumn(name = "genre_id", referencedColumnName = "genre_id"))
    private List<Genre> genres = new ArrayList<>();

}

@Data
@Entity
public class Genre {

    @Id
    @Column(name = "genre_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long genreId;

    @ManyToMany(mappedBy = "genres", fetch = FetchType.EAGER)
    private List<Film> films = new ArrayList<>();

}

And I have JpaRepositories with them.

The problem is that I get both films and genres ArrayLists as a link instead of array.
Here's how it looks:

 {
  "genreId" : 1,
  "name" : "Comedy",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/api/genres/1"
    },
    "genre" : {
      "href" : "http://localhost:8080/api/genres/1"
    },
    "films" : {
      "href" : "http://localhost:8080/api/genres/1/films"
    }
  }
}


Can anybody help me out?

Alice
  • 11
  • 1
  • Is this plain vanilla spring boot application or any library on top of it – silentsudo Jun 12 '20 at 12:18
  • @silentsudo Hi. Here are all dependencies that I used: spring-boot-starter-data-jpa, spring-boot-starter-data-rest, spring-boot-starter-web, mysql-connector-java and lombok – Alice Jun 12 '20 at 13:01
  • Please check this answer https://stackoverflow.com/questions/23264044/disable-hypertext-application-language-hal-in-json – silentsudo Jun 12 '20 at 13:05
  • https://stackoverflow.com/questions/37971312/spring-data-rest-in-plain-json-not-hal-format?noredirect=1&lq=1 – silentsudo Jun 12 '20 at 13:09
  • @silentsudo Thanks a lot :) I used Projection as it was mentioned in your first link and it worked. Could you post it as an answer to my question so that I could mark it as the best solution? – Alice Jun 12 '20 at 14:28
  • Thats ok XD have fun doing programming – silentsudo Jun 13 '20 at 12:44

0 Answers0