<p>I have added a map in my values.yaml file like below</p>
<pre><code>defaultview:
  journey:
    ce5f164c-ae0f-11e7-9220-c7137b83fb6a: 45
    abc: -1
    pqr: 30
</code></pre>
<p>I read this property in configmap like below</p>
<pre><code>defaultview.journey: {{ .Values.defaultview.journey }}
</code></pre>
<p>When I check configmap I see entry like below in cm</p>
<pre><code>defaultview.journey:
----
map[abc:-1 ce5f164c-ae0f-11e7-9220-c7137b83fb6a:45 pqr:30]
</code></pre>
<p>Java class is trying to bind this property into a Map&lt;String,Integer&gt; like below</p>
<pre><code>import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Data
@Component
@ConfigurationProperties(prefix = &quot;defaultview&quot;)
public class JourneyViewConfig {

    private Map&lt;String, Integer&gt; Journey = new HashMap&lt;&gt;();

}
</code></pre>
<p>I see error thrown while spring boot startup</p>
<pre><code>Failed to bind properties under 'defaultview.journey' to java.util.Map&lt;java.lang.String, java.lang.Integer&gt;:\\n\\n    Property: defaultview.journey\\n    Value: \\\&quot;map[abc:-1 ce5f164c-ae0f-11e7-9220-c7137b83fb6a:45 pqr:30]\\\&quot;\\n    Origin: \\\&quot;defaultview.journey\\\&quot; from property source \\\&quot;&lt;cm name&gt;\\\&quot;\\n    Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map&lt;java.lang.String, java.lang.Integer&gt;
</code></pre>
<p>Is there a way to inject Map directly from configmap to spring boot?</p>
<p>Edit 1:
I am able to read the values in map by adding this <strong>dirty code</strong></p>
<pre><code>private Map&lt;String, Integer&gt; parseConfigValue(String configValue) {
    Map&lt;String, Integer&gt; resultMap = new HashMap&lt;&gt;();

    String trimmedInput = configValue.trim();
    if (trimmedInput.startsWith(&quot;map[&quot;)) {
        trimmedInput = trimmedInput.substring(4, trimmedInput.length() - 1);
        String[] pairs = trimmedInput.split(&quot; &quot;);

        for (String pair : pairs) {
            String[] keyValue = pair.split(&quot;:&quot;);
            if (keyValue.length == 2) {
                String key = keyValue[0].trim();
                Integer value = Integer.parseInt(keyValue[1].trim());
                resultMap.put(key, value);
            }
        }
</code></pre>
<p>Is there a more subtle way of doing this?</p>

Prashant Raghav
<p>This line is problematic:</p>
<pre><code>defaultview.journey: {{ .Values.defaultview.journey }}
</code></pre>
<p>You're trying to include a structured variable as a simple string, so this is resulting in a ConfigMap that looks like:</p>
<pre><code>data:
  defaultview.journey_broken: map[abc:-1 ce5f164c-ae0f-11e7-9220-c7137b83fb6a:45 pqr:30]
</code></pre>
<p>That's not useful, as it's neither valid YAML nor JSON and probably isn't what your application is expecting.</p>
<p>You're going to need to use the <code>toYaml</code> function to render your structured variable as a block of YAML text. For example:</p>
<pre><code>data:
  defaultview.journey: |
{{ indent 4 (.Values.defaultview.journey | toYaml) }}
</code></pre>
<p>Which results in:</p>
<pre><code>data:
  defaultview.journey: |
    abc: -1
    ce5f164c-ae0f-11e7-9220-c7137b83fb6a: 45
    pqr: 30
</code></pre>
