I have the need to send to my back-end a JSON recursive array which contains several sorted objects and arrays inside.
From what I've read JSON doesn't guarantee that Json Objects are ordered, in fact my issue is that if I go in debug on the java endpoint, the array received randomly lose the order of "subchildren" array .
Although I'm not completely sure that is the problem because in my case I have an Array which contains an object which contains another array and it's this last array which lose the order not his parent object
How can I successfully send and receive between back-end and front-end this kind of structure (always created in the react front-end application) ?
E.g. this sample is sent to a post http://localhost:8080/dynasty/1 but the subchildren array lose it's order when received by the java endpoint (sometimes there is first the child2 or child3 which isn't correct)
dynasty_tree : [
{
name: father,
age: 50,
subchildren: [
{
name: child1,
age: 30,
subchildren: []
},
{
name: child2,
age: 28,
subchildren: []
},
{
name: child3,
age: 26,
subchildren: []
},
]
}
]
the data from front-end is sent with axios:
const handleSubmitForm = async (e) => {
const result = await axios.post( http://localhost:8080/dynasty/${id}, data );
}
java back-end method:
@PostMapping("/dynasty/{id}")
public ResponseEntity<?> savePeopleById(@RequestBody Iterable<person> peopleList, @PathVariable int id, BindingResult result){
thank you for the help