I am trying to make a Many-to-Many
link between the usuario
and permissao
classes, using the hibernate as a reference. But when I try to generate a JSON file of class usuario
the program loops and generates an unexpected file.
How to avoid this and make it limit the output file.
I'm using Spring Boot 2.0.2
Below are my classes:
User.Class
public class Usuario {
protected long id;
protected String nome;
private String senha;
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private List<Permissao> permissao;
}
Permission.class
public class Permissao{
protected long id;
protected String nome;
@ManyToMany(mappedBy = "permissao")
private List<Usuario> usuario;
}
SQL (Constraints have been removed for simplification)
CREATE TABLE usuario
(
id INT UNSIGNED AUTO_INCREMENT
PRIMARY KEY,
nome VARCHAR(45) NOT NULL,
senha VARCHAR(45) NOT NULL
)
CREATE TABLE usuario_permissao
(
usuario_id INT(11) UNSIGNED NOT NULL,
permissao_id INT(11) UNSIGNED NOT NULL
)
CREATE TABLE permissao
(
id INT UNSIGNED AUTO_INCREMENT
PRIMARY KEY,
nome VARCHAR(45) NOT NULL
)
and the JSON output
[{"id":1,"nome":"admin","senha":"admin","permissao":
[{"id":1,"nome":"admin","usuario":
[{"id":1,"nome":"admin","senha":"admin","permissao":
[{"id":1,"nome":"admin","usuario":
[{"id":1,"nome":"admin","senha":"admin","permissao":
[{"id":1,"nome":"admin","usuario":
[{"id":1,"nome":"admin","senha":"admin","permissao":
[{"id":1,"nome":"admin","usuario":