Kolargol00
Kolargol00

Reputation: 1887

Spring Boot YAML configuration with URL in key no longer loads correctly with version 2

I'm migrating my application from Spring Boot 1.5 to 2.0 and one of the YAML properties no longer loads correctly. The following configuration snippet:

myapp
  serviceUrls:
    'https://example.org/test': 'https://test.example.org/Endpoint'

is mapped to this configuration class:

@ConfigurationProperties(prefix = "myapp", ignoreUnknownFields = false)
public final class MyAppProperties {
  private Map<String, String> serviceUrls = new HashMap<>();
  //[...]
}

I couldn't find any mention of this in the migration guide. Has YAML parsing changed in Spring Boot 2? Is there a better way to write YAML maps with URLs as keys?

Upvotes: 13

Views: 5029

Answers (1)

Kolargol00
Kolargol00

Reputation: 1887

I should have checked GitHub issues... someone reported a similar problem. The solution is to use the "bracket syntax", which is unfortunately barely documented, wrapping the keys within brackets:

myapp
  serviceUrls:
    '[https://example.org/test]': 'https://test.example.org/Endpoint'

Upvotes: 29

Related Questions