I am trying to set a object value to null in properties file but it is always being returned as string. Here is the sample code along with the properties file.
File propertiesFile = new File('/opt/config.properties')
propertiesFile.withInputStream {
properties.load(it)
}
**config.properties**
spotConfig = null
println properties.spotConfig
But when I am trying to print the above value, it is always returning string whereas I want it to print a null object. How can I do that in groovy? Any help appreciated!
There is no concept of explicitly assigning null
in a properties file. The closest you can get is an empty string as you can read here .
spotConfig
Or you can simply not specify the key at all.
Properties
keys and values are strings. So you can't get a null
as value from a Properties
instance containing that key.
In both of these cases, the value will be returned as a string:
x=
y=null
properties.get("x")
will return ""
, and properties.get("y")
will return "null"
(the literal string).
What you have to do is propbably remove the key from the file altogether (don't add a spotConfig
key in the file) to get null
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.