advanceEncode function

dynamic advanceEncode(
  1. dynamic object
)

Implementation

dynamic advanceEncode(dynamic object) {
  if (object is DateTime) {
    return object.toIso8601String();
  }
  // a DTO in a response has no toJson(): its schema makes the map
  DtoSchema<Object>? schema = Dox().dtos.ofType(object.runtimeType);
  if (schema != null && schema is JsonObjectWriter) {
    return schema.toMap(object as Object);
  }
  // a plain `@Serialize()` class has no toJson(): its writer makes the map
  SerializeWriter? writer = Dox().ioc.jsonWriterOf(object.runtimeType);
  if (writer != null) return writer.toJsonValue(object as Object);
  return object.toJson();
}