}
return JSONObject.NULL;
}
// check for duplicate objects or circular references
ProcessedObject p = state.getProcessedObject(java);
// if this object hasn't been seen before, mark it as seen and continue forth
if (p == null) {
state.push(parent, java, ref);
} else {
//todo: make test cases to explicitly handle all 4 combinations of the 2 option
//todo: settings (both on the client and server)
// handle throwing of circular reference exception and/or serializing duplicates, depending
// on the options set in the serializer!
boolean foundCircRef = state.isAncestor(p, parent);
// throw an exception if a circular reference found, and the
// serializer option is not set to fixup these circular references
if (!_fixupCircRefs && foundCircRef) {
throw new MarshallException("Circular Reference");
}
// if its a duplicate only, and we aren't fixing up duplicates or if
// it is a primitive, and fixing up of primitives is not allowed then
// re-serialize the object into the json.
if (!foundCircRef
&& (!_fixupDuplicates || (!_fixupDuplicatePrimitives && isPrimitive(java)))) {
//todo: if a duplicate is being reserialized... it will overwrite the original location of the
//todo: first one found... need to think about the ramifications of this -- optimally, circ refs found
//todo: underneath duplicates need to point to the "original" one found, but they also need to be fixed
//todo: up to the correct location, of course.
state.push(parent, java, ref);
} else {
// generate a fix up entry for the duplicate/circular reference
state.addFixUp(p.getLocation(), ref);
return CIRC_REF_OR_DUPLICATE;
}
}
try {