-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
YamlPropertiesFactoryBean has empty string returned when empty array value is present in the YAML document #24879
Comments
As per #21310, an empty array in a YAML file gets converted to an empty String when using That's be design, since values in a As stated by @snicoll, conversion of an empty array to an empty string "corresponds to an empty comma-separated list of entries in the Properties format." So what exactly does not work for you? |
@sbrannen : I'm retrieving the git yml properties, store it in cache and provide the configuration properties. DataType mismatch is coming up. Can the framework be fixed to return the object as -> cards: "[ ]" instead of cards: "" ? For clarity to show empty String and empty Array get same o/p: Git hub entries Response from spring cloud config profile API: |
No. The properties format has no notion of an array.
If you have a small sample (that does not involve spring cloud config server) that shows how a data type mismatch is thrown, we can have a look to your use case. Please share that as a small project we can run ourselves (a zip or a link to a github repo). |
@snicoll : Please find the sample code in https://github.com/dhivyaarumugam/yaml-processing-validator. Follow the readMe to have the local setup : https://github.com/dhivyaarumugam/yaml-processing-validator/blob/master/README.md |
@snicoll : A PR i have raised from my fork : dhivyaarumugam@3536a21 |
Thanks for the sample. As I've indicated previously, the properties format has no notion of an array so you can't expect that to be available in any shape or form in the returned Your sample is just raw checking the Map and it doesn't demonstrate the DataType mismatch you've described (all values are of type I've added this: @Component
@ConfigurationProperties(prefix = "test")
public class TestProperties {
private String[] emptyArray;
public String[] getEmptyArray() {
return this.emptyArray;
}
public void setEmptyArray(String[] emptyArray) {
this.emptyArray = emptyArray;
}
} and the following config: test:
emptyArray: [] and when I inject |
@snicoll : In Spring cloud config, when propertySource is created it uses the map from yaml processor directly and doesn't have spring Binder involved in it. Yes Spring binder can help in case of a POJO not in our case. |
That makes total sense since the goal is to output a "properties view" of the configuration. There's nothing Spring Cloud Config should do about that.
You haven't shared what your case is in your sample so I can't say anything about that. I think this issue has run its course in the core framework though and I hope the rationale I've shared explains why we're not going to change this. |
This is related to #21310.
I'm using the latest spring boot version 2.2.6 and latest spring cloud config version 2.2.2.
I use GitHub as source of truth for fetching my configurations from base YAML file.
Check the property
cards: [""]
or justcards: []
in line number 4.The response I get from my service for fetching the configuration is as below snapshot for a default profile API to spring cloud config server.
Please find below snapshot with response : "default.oihs.cards": ""
Stack Overflow question: https://stackoverflow.com/questions/61096022/yamlpropertiesfactorybean-has-empty-string-returned-when-empty-array-value-is-pr
The text was updated successfully, but these errors were encountered: