1
Next people had a loop problem in my project when creating Json the application looped. I was able to solve the loop problem with the @Jsonmanagedreference, @Jsonbackreference annotation. However, an incomplete Json is being created following:
[{"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 :
customers":[{"id":6,"client":5,"garrafao":3,"quantity":3}
Comparing with the first object or even with the second element of the array of the second object it came complete.
How do I get everything complete? I’ll leave the github link with the project in the name branch Stackoverflow.
---------------- Edit --------------------------
I did some tests here and I realized that if the first Customer owns the garrafao in the second Customer he does not only carry the garrafao name his id, that is, the garrafaOne and garrafaoId attributes are not created in Json. Follows:
[{"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}]}]
Look I tried to do the Clientegarrafao class thing but it didn’t work out the same way, but it still paid off!
– Natanael Huochyton