question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SpringBoot2 ConfigurationProperties removes colon from yaml keys

See original GitHub issue

Until SpringBoot 1.5.9 I was using the application yaml to define a namespaced id with few properties. eg.

app:
    ids:
      "urn:test:id:12-34" :
        roles:
          - CREATE
          - ALLOW_ALL
      "urn:test:id:23-41" :
        roles:
          - DELETE
          - ALLOW_ALL

This was being read in as a Map

@ConfigurationProperties(prefix = "app")
@Data
@Component
public class IdProps {
  @Data
  public static class IdProps {
    private Map<String, Id> ids = new HashMap<>();
  }

  @Data
  public static class Id {
    private List<String> roles = new ArrayList<>();;
  }
}

The expectation was that this worked in SpringBoot2.

However, the Map keys in SPringBoot2 were as below “urntestid12-34” -> “IdProps.Id(roles=[CREATE, ALLOW_ALL])”

Expected behavior “urn:test🆔12-34” -> “IdProps.Id(roles=[CREATE, ALLOW_ALL])”

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
mbhavecommented, Dec 20, 2017

@balajeetm the new properties binder strips off all characters that are not alphanumeric or - so that properties can be read in a uniform manner. For map keys that have special characters in them, you can surround the key name with [] so that the key gets used as specified, for example, '[urn:test:id:12-34]'.

0reactions
mle-ensocommented, Jan 31, 2018

Thanks for your quick feedback… I’ll take a deeper look in your referenced issue and then proceed accordingly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Escaping a dot in a Map key in Yaml in Spring Boot
As a work around, you can use Spring's YamlMapFactoryBean to create a Yaml Map as it is. Then, you can use that map...
Read more >
Core Features - Spring
This section dives into the details of Spring Boot. Here you can learn about the key features that you may want to use...
Read more >
YAML to List of Objects in Spring Boot - Baeldung
Spring Boot provides the @ConfigurationProperties annotation to simplify the logic of mapping external configuration data into an object model.
Read more >
Spring @ConfigurationProperties using YAML
In general, you do not need to use quotation "" around string values in YAML. Quotation is requires if it: includes a colon...
Read more >
Spring Boot @ConfigurationProperties example - Mkyong.com
properties or yml file below, how we are going to map the values via @Value ? application.properties. #Logging logging.level.org.springframework ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found