Below are the JSON definitions that I am working with:
export class Company {
name: string;
trips : Trip[] = [];
}
export class Trip{
id: number;
name: string;
}
Within the component, there is a method that contains the following code:
const children = this.company.trips;
console.log(children.length);
When checking the console, it displays "undefined" for the length, indicating that it is not recognized as an array.
This snippet is part of the "company" object in the Java code:
@XmlElement(name = "trip")
private Set<Trip> trips = new HashSet<Trip>(0);
Here is a portion of the "company" object from the console:
{id: 1, user: {...},{...}
country: {code:"UK", id: 229}
trip: {id: 1, name: "ABC"}
I have also attempted to incorporate @XmlElementWrapper:
@XmlElementWrapper(name="trips")
@XmlElement(name = "trip")
private Set<Trip> trips = new HashSet<Trip>(0);
In this scenario, the response I receive looks like this:
"trips":{"trip":{"id":1,"name":"ABC"}}}}
I am looking to obtain an array/list and access its values through a loop. Can someone assist me with this issue? Do I need to make any changes on the Java side?
Thank you.