I have been using this monkey patch for a long time:
<monkey:patch description="Fix circular reference when field is RelationValue"
class="plone.app.content.utils"
original="custom_json_handler"
replacement=".monkey_patches.pac_utils_custom_json_handler"
/>
def pac_utils_custom_json_handler(obj):
#log.info('%s custom_json_handler called' % get_linenumber())
if obj == Missing.Value:
return None
if type(obj) in (datetime.datetime, datetime.date):
return obj.isoformat()
if type(obj) == DateTime:
dt = DateTime(obj)
return dt.ISO()
if type(obj) == set:
return list(obj)
# 20170418 fixed Circular reference
# return the id of the related object(s)
if type(obj) == RelationValue:
return obj.to_path.split('/')[-1]
if type(obj) == RelationList:
return list(item.to_path.split('/')[-1] for item in obj)
return obj