Jump to: navigation, search

Difference between revisions of "EclipseLink/Release/2.4.0/JAXB RI Extensions/Cycle Recoverable"

Line 18: Line 18:
 
<div style="width:800px">
 
<div style="width:800px">
 
<source lang="java">
 
<source lang="java">
 +
import java.util.*;
 
import javax.xml.bind.annotation.*;
 
import javax.xml.bind.annotation.*;
  
Line 24: Line 25:
  
 
   public String name;
 
   public String name;
   public List<Employee> employees;
+
   public List<Employee> employees = new ArrayList<Employee>();
  
 
}
 
}
Line 38: Line 39:
  
 
}
 
}
 +
</source>
 +
</div>
 +
 +
An object cycle would be created if you constructed the following objects:
 +
 +
<div style="width:800px">
 +
<source lang="java">
 +
Employee emp1 = new Employee();
 +
emp1.name = "Fred Smith";
 +
 +
Department dept1 = new Department();
 +
dept1.name = "Accounting";
 +
 +
emp1.dept = dept1;
 +
dept1.employees.add(emp1);
 
</source>
 
</source>
 
</div>
 
</div>

Revision as of 13:22, 1 June 2012

Design Documentation: CycleRecoverable

ER 372404

In the current JAXB RI, developed by Sun, there are a series of "proprietary" JAXB extensions that are available to provide advanced JAXB functionality outside of the JAXB spec (these extension classes reside in the com.sun.xml.bind package).

The CycleRecoverable interface allows the user to write their own logic to be used when object cycles are detected during marshal operations. When a cycle is detected, MOXy will invoke the onCycleDetected, which returns a "replacement" object for the one that caused the cycle.

This document will outline the design for an EclipseLink equivalent to this extension.


Example

Consider the following two classes:

import java.util.*;
import javax.xml.bind.annotation.*;
 
@XmlRootElement
public class Department {
 
   public String name;
   public List<Employee> employees = new ArrayList<Employee>();
 
}
public class Employee {
 
   public String name;
   public Department dept;
 
}

An object cycle would be created if you constructed the following objects:

Employee emp1 = new Employee();
emp1.name = "Fred Smith";
 
Department dept1 = new Department();
dept1.name = "Accounting";
 
emp1.dept = dept1;
dept1.employees.add(emp1);