I\'ve a classic spring web app with some spring crud repository.
I\'m trying to save my entities within a classic angular form and i\'m getting randomly this error :
I think this issue occurs only when you serialize for the first time an Exchange entity. Maybe Jackson save a "copy" of attributes for each Object ?
To prevent infinite loop, you added this annotation :
@JsonIgnoreProperties(value = {"exchange"})
@OneToMany(mappedBy = "exchange")
private List<HalfFlow> halfFlows;
So, my guess is Jackson "blacklist" property exchange of Halfflow bean.
Workaround : Use an ObjectMapper for each entity on your controller :
ObjectMapper mapper = new ObjectMapper();
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<HalfFlow> save(@RequestBody String json) throws JsonParseException, JsonMappingException, IOException {
HalfFlow node = mapper.readValue(json, HalfFlow.class);
HalfFlow halfflow = mapper.convertValue(node, HalfFlow.class);
As Alex said, to prevent the infinite recursion, you added this annotation
@JsonIgnoreProperties(value = {"exchange"})
@OneToMany(mappedBy = "exchange")
private List<HalfFlow> halfFlows;
So I actually solved this issue by adding the following to the annotation
@JsonIgnoreProperties(value = {"exchange"}, allowSetters = true)
@OneToMany(mappedBy = "exchange")
private List<HalfFlow> halfFlows;
This solution is better explained here https://softwareengineering.stackexchange.com/questions/300115/best-way-to-deal-with-hibernate-1-many-relationship-over-rest-json-service