This PR changes the handling of JSON keys in the CloudFoundry VCAP_SERVICES environment variable so that they represent only a single path segment at a time.
Before this change, if the JSON contained an object key with dots, the key would be treated as individual path segments, instead of a single one. E.g. the VCAP_SERVICES variable
{
"user-provided": [
{
"name": "test",
"label": "test-label",
"credentials": {
"key.with.dots": {
"username": "foo",
"password": "bar"
}
}
}
]
}
Would lead to the spring property:
vcap.services.test.credentials.key.with.dots.username=foo
Instead of the escaped version:
vcap.services.test.credentials[key.with.dots].username=foo
This causes problems e.g. when trying to bind these properties to a map, as it would not be filled with any values:
@ConfigurationProperties("vcap.services.test")
public class CfEnvCredentials {
public final Map<String, BasicAuthentication> credentials;
[...]
}
Comment From: pivotal-issuemaster
@schulzh Please sign the Contributor License Agreement!
Click here to manually synchronize the status of this Pull Request.
See the FAQ for frequently asked questions.
Comment From: pivotal-issuemaster
@schulzh Thank you for signing the Contributor License Agreement!
Comment From: philwebb
@schulzh What sort of generic types do you have on your Map? We should automatically deal with this for String
and scalar types (see this test). Do you have a small sample that show the problem that lead to you creating this PR?
Comment From: schulzh
I have a Map<String, BasicAuthentication>
, with this BasicAuthentication class:
public class BasicAuthentication extends Authentication {
public final String username;
public final String password;
}
This is meant to supply Authentication information for arbitrary hosts, which will be the keys of the map, therefore the dots in the keys.
I just tested a Map<String, String>
example and indeed, it worked. Sorry, I should have tested the actual example before. I'll edit the PR with the actual example.
Comment From: snicoll
@schulzh would you have time to revisit the PR based on Madura's feedback?
Comment From: mbhave
@schulzh Thank you for making your first contribution to Spring Boot. This has now been merged along with this addition.
Comment From: wilkinsona
Unfortunately, this change caused some unanticipated problems and we're going to have to revert it. Please see https://github.com/spring-projects/spring-boot/issues/20343 for details. We've opened https://github.com/spring-projects/spring-boot/issues/20400 to take another look at the problem. It's tentatively scheduled for 2.3.