Skip to content

: 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

Closed
jamesbradlee opened this issue Jun 14, 2024 · 3 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@jamesbradlee
Copy link

jamesbradlee commented Jun 14, 2024

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",
)
@jamesbradlee jamesbradlee changed the title : characters are removed from application.yaml when using @ConfigurationProperties : characters are removed from application.yaml keys in mapped values when using @ConfigurationProperties Jun 14, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 14, 2024
@quaff
Copy link
Contributor

quaff commented Jun 14, 2024

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) {

	}
}

@quaff
Copy link
Contributor

quaff commented Jun 14, 2024

Here is a workaround:

something:
  values[urn:some:specifier]: hello world
  values[urn:another:specifier]: cool stuff

@wilkinsona
Copy link
Member

Thanks, @quaff. That's not a workaround, it's the documented way to preserve keys as-is when binding to a map.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2024
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 14, 2024
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
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants