code: def enrich_json_objects_by_object_type(request, value):
      time_start_globally = time()
      if isinstance(value, list):
          json = [x.to_json() if hasattr(x, "to_json") else x for x in value]
      else:
          if isinstance(value, dict):
              json = value
          else:
              json = value.to_json()
      objects, nested = _collect_json_objects(json, by='object_type')
      for enricher_info in _get_OBJECT_TYPE_ENRICHER_ORDER():
          if len(enricher_info['object_types']) > 0:
              enricher_objects = flatten([objects.get(object_type, []) for object_type in enricher_info['object_types']])
              enricher_nested = any([nested.get(object_type, False) for object_type in enricher_info['object_types']])
          else:
              enricher_objects = flatten(objects.values())
              enricher_nested = any(nested.values())
          if len(enricher_objects) > 0:
              time_start = time()
              enricher_info['enricher'](request, enricher_objects, enricher_nested)
              LOGGER.debug('enrichment "{}" took {} seconds'.format(enricher_info['enricher_name'], time() - time_start))
              if not enricher_info['pure']:
                  objects, nested = _collect_json_objects(json, by='object_type')
      LOGGER.debug('The whole enrichment of json objects by their object_type took {} seconds.'.format(time() - time_start_globally))
      return json