readObject method

dynamic readObject(
  1. String? correlationId,
  2. ConfigParams parameters
)

Reads configuration file, parameterizes its content and converts it into JSON object.

  • correlationId (optional) transaction id to trace execution through call chain.
  • parameters values to parameters the configuration. Return a JSON object with configuration.

Implementation

dynamic readObject(String? correlationId, ConfigParams parameters) {
  if (super.getPath() == null) {
    throw ConfigException(
        correlationId, 'NO_PATH', 'Missing config file path');
  }

  try {
    // Todo: make this async?
    String? content = File(super.getPath()!).readAsStringSync();
    content = parameterize(content, parameters);
    var data = content != null ? loadYaml(content) : null;
    return data;
  } catch (e) {
    throw FileException(
            correlationId,
            'READ_FAILED',
            'Failed reading configuration ' +
                super.getPath()! +
                ': ' +
                e.toString())
        .withDetails('path', super.getPath())
        .withCause(e);
  }
}