spring-boothashmapyamlconfigurationproperties

SpringBoot @ConfigurationProperties issue with key that contains /


I don't know if it's normal behaviour or a bug. I've created a ConfiguationProperties :

@Configuration
@ConfigurationProperties("sample")
public class MyConfig {


    private Map<String, String> labels;


    public Map<String, String> getLabels() {
        return labels;
    }

    public void setLabels(Map<String, String> labels) {
        this.labels = labels;
    }
}

And a Yaml File :

sample:
  labels:
    simple: value1
    net.gcuisinier: value2
    net.gcuisinier/env: value3

But for an unknown reason, the result map contains

simple=value1
net.gcuisinier=value2
net.gcuisinierenv=value3 

Without the "/" in the last key.

Does anyone know if it's normal ? Or it's a bug?

You can find a simple project that reproduce the "problem" here : https://github.com/gcuisinier/spring-issue


Solution

  • I think this is the normal behaviour. There is a section in the documentation explaining how to keep the escaped characters (/ in you case).

    sample:
      labels:
        simple: value1
        net.gcuisinier: value2
        "[net.gcuisinier/env]": value3
    

    Spring boot documentation: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-relaxed-binding-maps