0

I have an application in front end i use angular and back end i use Spring boot. In my front end i must upload a CSV file that insert data in tables. So i send data to the backend which save it. My problem: i have a class Individus with relation @OneToMany to others class like as comptes. So when i try to get All individus with this Rest service : http://localhost:8080/api/individus, i have a parsing json data error.

at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) ~[jackson-databind-2.9.6.jar:2.9.6]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:727) ~[jackson-databind-2.9.6.jar:2.9.6]

Here is my class Individus:

@Entity 

public class Individu implements Serializable {

@Id
private String nui;
private int civility; 
private String lastName;
private String useName;
private String firstName;
@Temporal(TemporalType.DATE)
@JsonFormat(pattern="dd/MM/yyyy")
private Date birthDate;
private String birthPlace;
private String birthCountry;
private String birthCountryLib;
private String nationality;
@OneToMany(mappedBy="individu", fetch = FetchType.LAZY)
private Collection<Compte> comptes;
@OneToMany(mappedBy="individu", fetch = FetchType.LAZY)
private Collection<Adresse> adresses;
@OneToMany(mappedBy="individu", fetch = FetchType.LAZY)
private Collection<Contact> contacts;
@OneToMany(mappedBy="individu", fetch = FetchType.LAZY)
private Collection<Iban> ibans;ode here

Is some one have a solution for me?

2 Answers 2

2

You didn't provide enough of the stacktrace to show what the actual error is, but I suspect that you're running into a problem with a circular graph, as the objects in your Individu class' collections (e.g. Compte, Ardresse) probably hold a reference to the parent Individu instance.

The solution in that case is to add a @JsonIgnore annotation to the children's references to the parent. This is most likely an attribute in the child that is currently marked with an @ManyToOne annotation.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah it was a circular graph. And the anotation @JsonIgnore was the solution. Thanks you for your help
0

this is another solution

public class Produit{.....
@ManyToOne(optional=false,fetch=FetchType.LAZY)
@JsonBackReference
private Category category;....}


public class Category{....
@OneToMany(fetch=FetchType.LAZY,mappedBy="category")
@JsonManagedReference
private Collection<Produit> produits;....}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.