org.pipservices3.components.config.JsonConfigReader Maven / Gradle / Ivy
package org.pipservices3.components.config;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.pipservices3.commons.config.ConfigParams;
import org.pipservices3.commons.errors.*;
import com.fasterxml.jackson.core.type.*;
import com.fasterxml.jackson.databind.*;
/**
* Config reader that reads configuration from JSON file.
*
* The reader supports parameterization using Handlebars template engine.
*
* ### Configuration parameters ###
*
* - path: path to configuration file
*
- parameters: this entire section is used as template parameters
*
- ...
*
*
* ### Example ###
*
* {@code
* ======== config.json ======
* { "key1": "{{KEY1_VALUE}}", "key2": "{{KEY2_VALUE}}" }
* ===========================
*
* JsonConfigReader configReader = new JsonConfigReader("config.json");
*
* ConfigParams parameters = ConfigParams.fromTuples("KEY1_VALUE", 123, "KEY2_VALUE", "ABC");
* configReader.readConfig("123", parameters);
* }
*
* @see IConfigReader
* @see FileConfigReader
*/
public class JsonConfigReader extends FileConfigReader {
private static ObjectMapper jsonMapper = new ObjectMapper();
private static TypeReference