cfg4j / cfg4j

Modern configuration library for distributed apps written in Java.

Home Page:http://cfg4j.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

arkadutta87 opened this issue · comments

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

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.