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

Cannot read a Map<String,Integer> if present in a yaml file #251

Open
arkadutta87 opened this issue Apr 25, 2018 · 1 comment
Open

Cannot read a Map<String,Integer> if present in a yaml file #251

arkadutta87 opened this issue Apr 25, 2018 · 1 comment

Comments

@arkadutta87
Copy link

arkadutta87 commented Apr 25, 2018

I have the following configuration : ---
app-config.yml -

reksio:
  awake: true
  bornIn : Kolkata
  birthYear : 1987
  friends : 
   - Kulbeer
   - Anil
   - Tapas
  homepage : https://en.wikipedia.org/wiki/Arka_Dutta/
  points: 
    Math : 92
    PE : 99
    Bengali : 90

My Config file code --

public interface ReksioConfig {

  Boolean awake();

  String bornIn();

  Integer birthYear();

  List<String> friends();

  String homepage();

  Map<String, Integer> points();

}

Now when I do the following -
ReksioConfig reksioConfig = configurationProvider.bind("reksio", ReksioConfig.class); --
in the main class -

It throws this exception ---
java.util.NoSuchElementException: No configuration with key: reksio.points

I debugged your code to find out the issue --
org.cfg4j.source.context.propertiesprovider.YamlBasedPropertiesProvider#getProperties

line 55 - 56

Map<String, Object> yamlAsMap = convertToMap(object);
        properties.putAll(flatten(yamlAsMap));

org.cfg4j.source.context.propertiesprovider.FormatBasedPropertiesProvider#flatten

if (value instanceof Map) {
        Map<String, Object> subMap = flatten((Map<String, Object>) value);

        for (String subkey : subMap.keySet()) {
          result.put(key + "." + subkey, subMap.get(subkey));
        }
      }

This is the issue you faltten it out --

org.cfg4j.provider.SimpleConfigurationProvider#getProperty(java.lang.String)
are these lines --

Object property = configurationSource.getConfiguration(environment).get(key);

      if (property == null) {
        throw new NoSuchElementException("No configuration with key: " + key);
      }

Point is how to do I acheive Map<K,V> map -- inside my config where map is the class variable as itself is not a class/interface--

Kindly help I really want to use cfg4j it does a lot of task which we have to build otherwise. But map is a real requirement

@simenflatby
Copy link

I have the following configuration : ---
app-config.yml -

reksio:
  awake: true
  bornIn : Kolkata
  birthYear : 1987
  friends : 
   - Kulbeer
   - Anil
   - Tapas
  homepage : https://en.wikipedia.org/wiki/Arka_Dutta/
  points: 
    Math : 92
    PE : 99
    Bengali : 90

My Config file code --

public interface ReksioConfig {

  Boolean awake();

  String bornIn();

  Integer birthYear();

  List<String> friends();

  String homepage();

  Map<String, Integer> points();

}

Now when I do the following -
ReksioConfig reksioConfig = configurationProvider.bind("reksio", ReksioConfig.class); --
in the main class -

It throws this exception ---
java.util.NoSuchElementException: No configuration with key: reksio.points

I debugged your code to find out the issue --
org.cfg4j.source.context.propertiesprovider.YamlBasedPropertiesProvider#getProperties

line 55 - 56

Map<String, Object> yamlAsMap = convertToMap(object);
        properties.putAll(flatten(yamlAsMap));

org.cfg4j.source.context.propertiesprovider.FormatBasedPropertiesProvider#flatten

if (value instanceof Map) {
        Map<String, Object> subMap = flatten((Map<String, Object>) value);

        for (String subkey : subMap.keySet()) {
          result.put(key + "." + subkey, subMap.get(subkey));
        }
      }

This is the issue you faltten it out --

org.cfg4j.provider.SimpleConfigurationProvider#getProperty(java.lang.String)
are these lines --

Object property = configurationSource.getConfiguration(environment).get(key);

      if (property == null) {
        throw new NoSuchElementException("No configuration with key: " + key);
      }

Point is how to do I acheive Map<K,V> map -- inside my config where map is the class variable as itself is not a class/interface--

Kindly help I really want to use cfg4j it does a lot of task which we have to build otherwise. But map is a real requirement

Can confirm that this is a bug. It works if you do

points: Math=92,PE=99,Bengali=90

, but that does not make sense to do in a yaml file.

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