Skip to content

Instantly share code, notes, and snippets.

@2m
Created July 10, 2014 09:07
Show Gist options
  • Save 2m/941ed15336d92748cd39 to your computer and use it in GitHub Desktop.
Save 2m/941ed15336d92748cd39 to your computer and use it in GitHub Desktop.
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import java.util.Map;
import java.util.HashMap;
public class ConfigOverrideFromCode {
static public void main(String[] args) {
String config = "system {\n" +
" administrator = ${who-knows}\n" +
" developer = ${to-be-assigned-later}\n" +
"}";
Map<String, String> values = new HashMap<String, String>();
values.put("who-knows", "jon");
values.put("to-be-assigned-later", "kate");
Config original = ConfigFactory
.parseString(config)
.resolveWith(ConfigFactory.parseMap(values));
System.out.println(original.getString("system.administrator"));
System.out.println(original.getString("system.developer"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment