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 {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"marshall class {0}",
java.getClass().getName());
}
final ISerializer s = this.getSerializer(java.getClass(), null);
if (s != null) {
return s.marshall(state, parent, java);
}
throw new MarshallException("can't marshall " + java.getClass().getName());
} finally {
state.pop();
}
}