toJson method

  1. @override
Object? toJson([
  1. O? obj,
  2. JsonEncoder? jsonEncoder,
  3. bool duplicatedEntitiesAsID = false,
  4. bool? autoResetEntityCache,
])
override

Returns a JSON. If the class implements toJson calls it.

  • If obj is not provided, uses object as instance.

Implementation

@override
Object? toJson(
    [O? obj,
    JsonEncoder? jsonEncoder,
    bool duplicatedEntitiesAsID = false,
    bool? autoResetEntityCache]) {
  obj ??= object;
  if (obj == null) return null;

  if (hasMethodToJson) {
    var json = callMethodToJson(obj);

    if (jsonEncoder != null) {
      return jsonEncoder.toJson(json,
          duplicatedEntitiesAsID: duplicatedEntitiesAsID,
          autoResetEntityCache: autoResetEntityCache);
    } else {
      return json;
    }
  }

  return toJsonFromFields(
      obj: obj,
      jsonEncoder: jsonEncoder,
      duplicatedEntitiesAsID: duplicatedEntitiesAsID,
      autoResetEntityCache: autoResetEntityCache);
}