I'm having trouble setting null as a property value.
This is how the value is defined in YAML file:
my-property: null
This is how I inject it in code:
@Value("${my-property}")
private String myProperty;
For some reason, Spring keeps injecting an empty string ("") instead of null. Am I missing something or is this an error in Spring?
You can't, but this is not because YAML. YAML supports null as per:
Empty field in yaml
This is because of a Spring processor class, which turns "null" values into empty strings, see here:
https://github.com/spring-projects/spring-framework/issues/19986
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With