@JsonIgnore
annotation not working and i am not using Spring Framework
here is my code below:
import Plat.Hibernate.Util.DataBaseObject;
import org.codehaus.jackson.annotate.*;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Parent implements DataBaseObject{
private int id;
private String name;
@JsonIgnore
private List<Child> child;
public Parent(){
child = new ArrayList<>();
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@OneToMany(mappedBy = "parent",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JsonIgnore
public List<Child> getChild() {
return child;
}
@JsonIgnore
public void setChild(List<Child> child) {
this.child = child;
}
}
and the other class:
import org.codehaus.jackson.annotate.*;
import javax.persistence.*;
@Entity
public class Child implements DataBaseObject{
private int id;
private String name;
@JsonIgnore
private Parent parent;
public Child() {
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
@JsonIgnore
public Parent getParent() {
return parent;
}
@JsonIgnore
public void setParent(Parent parent) {
this.parent = parent;
}
}
and i am using Maven building tool in my project so this is the dependency for the @JsonIgnore
annotation:
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-lgpl</artifactId>
<version>1.9.13</version>
</dependency>
The problem is that when i use REST API request on this entity i get infinite loop (error 500 Internal Error) so i need to use the @JsonIgnore annotation to avoid this loop and it is not working