With a configuration properties class like this:
@ConfigurationProperties(prefix = "something")
data class MyConfigurationProperties(val values: Map<String, String>)
I would expect to be able to provide the following application.yaml:
something.values:
"urn:some:specifier": hello world
"urn:another:specifier": cool stuff
And then expect to receive MyConfigurationProperties.values as:
mapOf(
"urn:some:specifier" to "hello world",
"urn:another:specifier" to "cool stuff",
)
But the actual received values are:
mapOf(
"urnsomespecifier" to "hello world",
"urnanotherspecifier" to "cool stuff",
)
Comment From: quaff
It can be reproduced by java:
package com.example.demo;
import java.util.Map;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import com.example.demo.DemoApplication.MyConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(MyConfigurationProperties.class)
public class DemoApplication {
public static void main(String[] args) {
try (var ctx = SpringApplication.run(DemoApplication.class, args)) {
System.out.println(ctx.getBean(MyConfigurationProperties.class));
}
}
@ConfigurationProperties(prefix = "something")
public record MyConfigurationProperties(Map<String, String> values) {
}
}
Comment From: quaff
Here is a workaround:
something:
values[urn:some:specifier]: hello world
values[urn:another:specifier]: cool stuff
Comment From: wilkinsona
Thanks, @quaff. That's not a workaround, it's the documented way to preserve keys as-is when binding to a map.