public void convert(final Object item, final Converter converter) {
if (getMapper().isImmutableValueType(item.getClass())) {
// strings, ints, dates, etc... don't bother using references.
converter.marshal(item, writer, this);
} else {
final Path currentPath = pathTracker.getPath();
final Id<R> existingReference = references.lookupId(item);
if (existingReference != null && existingReference.getPath() != currentPath) {
final String attributeName = getMapper().aliasForSystemAttribute("reference");
if (attributeName != null) {
writer.addAttribute(attributeName, createReference(currentPath, existingReference.getItem()));
}
} else {
final R newReferenceKey = existingReference == null
? createReferenceKey(currentPath, item)
: existingReference.getItem();
if (lastPath == null || !currentPath.isAncestor(lastPath)) {
fireValidReference(newReferenceKey);
lastPath = currentPath;
references.associateId(item, new Id<R>(newReferenceKey, currentPath));
}
converter.marshal(item, writer, new ReferencingMarshallingContext<R>() {