Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No configuration setting found for key 'roles.“test@test.com”' #593

Open
emoleumassi opened this issue Oct 5, 2018 · 1 comment
Open

Comments

@emoleumassi
Copy link

My java Code to read a role in the property-file:

class ConfigIO {

    private final transient Supplier<Config> cfg = new Once<>(ConfigFactory::load);

    @PostConstruct
    private void init() {
        cfg.get();
    }

    public Optional<String> getRole(String userName) {
        String path = String.format("roles.\"%s\"", userName);
        if (!cfg.get().hasPath(path)) {
            return Optional.empty();
        }
        return Optional.of(cfg.get().getString(path));
    }

With this call:

new ConfigIO().getRole("test@test.com")

Here a part of my test.properties:

roles."test@test.com"="admin"
roles."testA@test.com"="editor"

Method threw com.typesafe.config.ConfigException$Missing exception.

How can i read this property with Quotes?

@havocp
Copy link
Collaborator

havocp commented Oct 5, 2018

I believe .properties files don't have any special meaning for quotes; here is the spec: https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader)

If you do a cfg.render() you can see how the properties have been parsed and adapt accordingly. You may find it less confusing to use ConfigObject.get (cfg.root.get("roles").get("\"test@test.com\"") perhaps) since it avoids also having to escape through the path syntax. See https://lightbend.github.io/config/latest/api/com/typesafe/config/ConfigObject.html#get-java.lang.Object-

Note section "paths, keys, and Config vs ConfigObject" in https://lightbend.github.io/config/latest/api/com/typesafe/config/Config.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants