YamlPropertiesFactoryBean has empty string returned when empty array value is present in the YAML document
See original GitHub issueThis 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 just cards: []
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
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Reading a map from yaml in Java getting null - Stack Overflow
I had the same problem with different generic types and I solved it by initializing the map member and remove the setter method,...
Read more >24. Externalized Configuration - Spring
You can use properties files, YAML files, environment variables and command-line arguments to externalize configuration. Property values can be injected ...
Read more >How to represent null values in YAML - Educative.io
Unknown or undefined values: When the value of a data element is unknown or undefined, null can be used as its value. Empty...
Read more >Arrays | Dev Cheatsheets - Michael Currin
But, you can split an empty string. Or you can define an array in your frontmatter and then use that. Define an array...
Read more >YamlProcessor (spring-beans 5.2.8.RELEASE API) - javadoc.io
Set the supported types that can be loaded from YAML documents. ... supportedTypes - the supported types, or an empty array to clear...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Map
.Your sample is just raw checking the Map and it doesn’t demonstrate the DataType mismatch you’ve described (all values are of type
String
). If you need to bind this to an Array, then whatever binder you have should account for the fact that an empty String bound to an Array leads to an empty array. The Spring Boot binder does that for you so perhaps you should be using that?I’ve added this:
and the following config:
and when I inject
TestProperties
,getEmptyArray()
returns an empty array. I am going to close this now as the sample works as designed.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.