-
Notifications
You must be signed in to change notification settings - Fork 41.2k
:
characters are removed from application.yaml
keys in mapped values when using @ConfigurationProperties
#41099
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
Labels
status: invalid
An issue that we don't feel is valid
Comments
:
characters are removed from application.yaml
when using @ConfigurationProperties
:
characters are removed from application.yaml
keys in mapped values when using @ConfigurationProperties
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) {
}
} |
Here is a workaround: something:
values[urn:some:specifier]: hello world
values[urn:another:specifier]: cool stuff |
Thanks, @quaff. That's not a workaround, it's the documented way to preserve keys as-is when binding to a map. |
quaff
added a commit
to quaff/spring-boot
that referenced
this issue
Oct 28, 2024
Given: ```yaml my: map: "/key": "value" ``` --- Before this commit: It's equivalent to ```yaml my: map: "[key]": "value" # "[/key]" is expected ``` Such counter-intuitive behavior will confuse developers, there are several reported issues, incomplete list: spring-projectsGH-41099 spring-projectsGH-29582 spring-projectsGH-24548 --- After this commit: ``` *************************** APPLICATION FAILED TO START *************************** Description: Failed to bind properties under 'my.map' to java.util.Map<java.lang.String, java.lang.String>: Reason: java.lang.IllegalArgumentException: Please rewrite key '/key' to '[/key]' and surround it with quotes if YAML is using Action: Update your application's configuration ``` --- See spring-projectsGH-42802
quaff
added a commit
to quaff/spring-boot
that referenced
this issue
Oct 28, 2024
Given: ```yaml my: map: "/key": "value" ``` --- Before this commit: It's equivalent to ```yaml my: map: "[key]": "value" # "[/key]" is expected ``` Such counter-intuitive behavior will confuse developers, there are several reported issues, incomplete list: spring-projectsGH-41099 spring-projectsGH-29582 spring-projectsGH-24548 --- After this commit: ``` *************************** APPLICATION FAILED TO START *************************** Description: Failed to bind properties under 'my.map' to java.util.Map<java.lang.String, java.lang.String>: Reason: java.lang.IllegalArgumentException: Please rewrite key '/key' to '[/key]' and surround it with quotes if YAML is using Action: Update your application's configuration ``` --- See spring-projectsGH-42802
quaff
added a commit
to quaff/spring-boot
that referenced
this issue
Oct 28, 2024
Given: ```yaml my: map: "/key": "value" ``` --- Before this commit: It's equivalent to ```yaml my: map: "[key]": "value" # "[/key]" is expected ``` Such counter-intuitive behavior will confuse developers, there are several reported issues, incomplete list: spring-projectsGH-41099 spring-projectsGH-29582 spring-projectsGH-24548 --- After this commit: ``` *************************** APPLICATION FAILED TO START *************************** Description: Failed to bind properties under 'my.map' to java.util.Map<java.lang.String, java.lang.String>: Reason: java.lang.IllegalArgumentException: Please rewrite key '/key' to '[/key]' and surround it with quotes if YAML is using Action: Update your application's configuration ``` --- See spring-projectsGH-42802
quaff
added a commit
to quaff/spring-boot
that referenced
this issue
Oct 28, 2024
Given: ```yaml my: map: "/key": "value" ``` --- Before this commit: It's equivalent to ```yaml my: map: "[key]": "value" # "[/key]" is expected ``` Such counter-intuitive behavior will confuse developers, there are several reported issues, incomplete list: spring-projectsGH-41099 spring-projectsGH-29582 spring-projectsGH-24548 --- After this commit: ``` *************************** APPLICATION FAILED TO START *************************** Description: Failed to bind properties under 'my.map' to java.util.Map<java.lang.String, java.lang.String>: Reason: java.lang.IllegalArgumentException: Please rewrite key '/key' to '[/key]' and surround it with quotes if YAML is using Action: Update your application's configuration ``` --- See spring-projectsGH-42802
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
With a configuration properties class like this:
I would expect to be able to provide the following
application.yaml
:And then expect to receive
MyConfigurationProperties.values
as:But the actual received values are:
The text was updated successfully, but these errors were encountered: