Consider the known employee/manager relation ship
public class Employee
{
public Employee manager;
public List<Employee> employees;
}
what i want is a way to marshall an employee such that all the child employees will be marshalled, the parent manager employee also be marshalled. without an infinite cycle loop.
As explained here , you can use the @XmlIDREF
annotation to avoid cyclic references.
Add a unique identifier to your employee and annotate it with @XmlID
, and annotate your possible cyclic references with @XmlIDREF
:
@XmlRootElement
class Employee {
@XmlID string id;
@XmlIDREF Employee manager;
@XmlIDREF List<Employee> _employees;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.