Next staff was experiencing a loop problem in my project when creating the Json application looping. I was able to solve the loop problem with the annotation @JsonManagedReference, @JsonBackReference. But an Incomplete Json is being created:
[{"clienteId":3,"clienteNome":"Teste","clienteRua":"Nestor Barbosa","clienteNumero":890,"clienteComplemento":null,"clienteGarrafaos":[{"id":3,"cliente":3,"garrafao":{"garrafaoId":3,"garrafaoNome":"Cristal"},"quantidade":0}]},
{"clienteId":5,"clienteNome":"Natanael","clienteRua":"Nestor Barbosa","clienteNumero":890,"clienteComplemento":null,"clienteGarrafaos":[{"id":6,"cliente":5,"garrafao":3,"quantidade":3},{"id":5,"cliente":5,"garrafao":{"garrafaoId":5,"garrafaoNome":"Pet"},"quantidade":3}]}]
If you look at the array of the second object in the first element, you will see the following:
Comparing with the first object or even the second element of the array of the second object, it came complete.
How to make everything come complete? I'll leave the github link with the project in the StackOverflow branch.
---------------- Edit --------------------------
I made some tests here and realized that if the first Client has the bottle in the second Client it does not have the bottle name only the id of it, that is, the bottle attributesName and bottleId is not created in Json. Following:
[{"clienteId":3,"clienteNome":"Teste","clienteRua":"Nestor Barbosa","clienteNumero":890,"clienteComplemento":null,"clienteGarrafaos":[{"id":3,"garrafao":{"garrafaoId":3,"garrafaoNome":"Cristal"},"quantidade":0},{"id":7,"garrafao":{"garrafaoId":5,"garrafaoNome":"Pet"},"quantidade":3}]},
{"clienteId":5,"clienteNome":"Natanael","clienteRua":"Nestor Barbosa","clienteNumero":890,"clienteComplemento":null,"clienteGarrafaos":[{"id":6,"garrafao":3,"quantidade":3},{"id":5,"garrafao":5,"quantidade":3}]}]